chiark / gitweb /
NEW etc.: Use NEW at non-formulaic call sites
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 7 Oct 2014 19:51:05 +0000 (20:51 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 21 Oct 2014 00:07:13 +0000 (01:07 +0100)
Manually replace calls to safe_malloc with NEW.  Calls where
safe_malloc was used to allocate a byte array (or a string buffer) are
left alone.

Some simple calls to allocate a single object are replaced with NEW.
(in COMM_APPLY, init_log, resolve_request, transform_cbcmac_module,
TRANSFORM_CREATE_CORE).

Some calls which were allocating arrays are replaced with NEW_ARY
(in dict_keys, ipset_new).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
comm-common.h
conffile.c
ipaddr.c
log.c
resolver.c
transform-cbcmac.c
transform-common.h

index 6dad9ef..b1cd9c0 100644 (file)
@@ -34,7 +34,7 @@ bool_t comm_notify(struct comm_notify_list *notify, struct buffer_if *buf,
 void comm_apply(struct commcommon *cc, void *st);
 
 #define COMM_APPLY(st,cc,prefix,desc,loc)              \
-    (st)=safe_malloc(sizeof(*(st)), desc "_apply");    \
+    NEW(st);                                           \
     (cc)->loc=loc;                                     \
     (cc)->cl.description=desc;                         \
     (cc)->ops.sendmsg=prefix##sendmsg;                 \
index 84f4960..f5a10a1 100644 (file)
@@ -545,7 +545,7 @@ cstring_t *dict_keys(dict_t *dict)
 {
     atom_t *r, *j;
     struct entry *i;
-    r=safe_malloc(sizeof(*r)*(dict->size+1),"dict_keys");
+    NEW_ARY(r,dict->size+1);
     for (i=dict->entries, j=r; i; i=i->next, j++) {
        *j=i->key;
     }
index aa770f8..4b5b48a 100644 (file)
--- a/ipaddr.c
+++ b/ipaddr.c
@@ -58,7 +58,7 @@ struct ipset *ipset_new(void)
     NEW(r);
     r->l=0;
     r->a=DEFAULT_ALLOC;
-    r->d=safe_malloc(sizeof(*r->d)*r->a,"ipset_new:data");
+    NEW_ARY(r->d,r->a);
     return r;
 }
 
diff --git a/log.c b/log.c
index a17032b..a2e24ae 100644 (file)
--- a/log.c
+++ b/log.c
@@ -274,7 +274,7 @@ struct log_if *init_log(list_t *ll)
     if (!l) {
        fatal("init_log: no log");
     }
-    r=safe_malloc(sizeof(*r), "init_log");
+    NEW(r);
     r->st=l;
     r->vlogfn=log_vmulti;
     r->buff[0]=0;
index e9f42f1..6f6588f 100644 (file)
@@ -75,7 +75,7 @@ static bool_t resolve_request(void *sst, cstring_t name,
        return True;
     }
 
-    q=safe_malloc(sizeof *q,"resolve_request");
+    NEW(q);
     q->cst=cst;
     q->comm=comm;
     q->port=port;
index ebf4702..f748792 100644 (file)
@@ -337,7 +337,7 @@ void transform_cbcmac_module(dict_t *dict)
        const char *errmsg;
        int i;
 
-       tr = safe_malloc(sizeof(struct transform),"test transform");
+       NEW(tr);
        tr->max_seq_skew = 20;
        ti = transform_create(tr);
 
index eea03c6..af62738 100644 (file)
@@ -80,7 +80,7 @@ typedef uint32_t recvbitmap_type;
 
 #define TRANSFORM_CREATE_CORE                          \
        struct transform_inst *ti;                      \
-       ti=safe_malloc(sizeof(*ti),"transform_create"); \
+       NEW(ti);                                        \
        /* mlock XXX */                                 \
        ti->ops.st=ti;                                  \
        ti->ops.setkey=transform_setkey;                \