chiark / gitweb /
NEW etc.: Use NEW in all obvious places
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 7 Oct 2014 19:31:26 +0000 (20:31 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 21 Oct 2014 00:07:12 +0000 (01:07 +0100)
Entirely automatic conversion, using the following Perl rune:

  perl -i~ -pe 's#^(\s+)(\w+)=safe_malloc\(sizeof\(\*\2\),"[^"]+"\);$#$1NEW($2);#' *.c conffile.fl conffile.y

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
21 files changed:
comm-common.c
conffile.c
conffile.fl
conffile.y
dh.c
ipaddr.c
log.c
md5.c
netlink.c
process.c
random.c
resolver.c
rsa.c
secnet.c
sha1.c
site.c
slip.c
transform-cbcmac.c
transform-eax.c
tun.c
util.c

index d880055cbe42a1f4d253cc4ca0d58c76231e682c..7528e924ced75647ad3c6f537b43486fe54d1bd6 100644 (file)
@@ -7,7 +7,7 @@ void comm_request_notify(void *commst, void *nst, comm_notify_fn *fn)
     struct commcommon *st=commst;
     struct comm_notify_entry *n;
     
-    n=safe_malloc(sizeof(*n),"comm_request_notify");
+    NEW(n);
     n->fn=fn;
     n->state=nst;
     LIST_INSERT_HEAD(&st->notify, n, entry);
index 0bd4e33bb3d3f9e5ee4c709e3ca701485ab75377..3ffbd9fd8274c2f3d3ceca8482770ae17951740d 100644 (file)
@@ -75,7 +75,7 @@ static void dict_iadd(dict_t *dict, atom_t key, list_t *val)
     if (dict_ilookup_primitive(dict, key)) {
        fatal("duplicate key \"%s\" in dictionary",key);
     }
-    e=safe_malloc(sizeof(*e),"dict_add");
+    NEW(e);
     e->next=dict->entries;
     e->key=key;
     e->val=val;
@@ -89,7 +89,7 @@ static dict_t *dict_new(dict_t *parent)
 {
     dict_t *d;
 
-    d=safe_malloc(sizeof(*d),"dict_new");
+    NEW(d);
     d->parent=parent;
     d->search=NULL;
     d->entries=NULL;
@@ -100,7 +100,7 @@ static dict_t *dict_new(dict_t *parent)
 static struct p_node *node_copy(struct p_node *n)
 {
     struct p_node *r;
-    r=safe_malloc(sizeof(*r),"node_copy");
+    NEW(r);
     *r=*n;
     return r;
 }
@@ -250,7 +250,7 @@ static item_t *new_item(enum types type, struct cloc loc)
 {
     item_t *i;
 
-    i=safe_malloc(sizeof(*i),"new_item");
+    NEW(i);
     i->type=type;
     i->loc=loc;
     return i;
@@ -518,7 +518,7 @@ atom_t intern(cstring_t s)
 
     if (!i) {
        /* Did't find it; create a new one */
-       i=safe_malloc(sizeof(*i),"intern: alloc list entry");
+       NEW(i);
        i->a=safe_strdup(s,"intern: alloc string");
        i->next=atoms;
        atoms=i;
@@ -577,7 +577,7 @@ static list_t *list_copy(list_t *a)
     l=NULL;
     r=NULL;
     for (i=a; i; i=i->next) {
-       b=safe_malloc(sizeof(*b),"list_copy");
+       NEW(b);
        if (l) l->next=b; else r=b;
        l=b;
        b->item=i->item;
@@ -601,7 +601,7 @@ list_t *list_append(list_t *list, item_t *item)
 {
     list_t *l;
 
-    l=safe_malloc(sizeof(*l),"list_append");
+    NEW(l);
     l->item=item;
     l->next=NULL;
 
@@ -627,7 +627,7 @@ list_t *new_closure(closure_t *cl)
 void add_closure(dict_t *dict, cstring_t name, apply_fn apply)
 {
     closure_t *c;
-    c=safe_malloc(sizeof(*c),"add_closure");
+    NEW(c);
     c->description=name;
     c->type=CL_PURE;
     c->apply=apply;
index 7228c9e8fa6cd672ea5a3ac480d8328fc161cede..b72bc0540f8a585badd32fb26ca9ae6148a7d434 100644 (file)
@@ -42,7 +42,7 @@ static struct p_node *leafnode(uint32_t type)
 {
        struct p_node *r;
 
-       r=safe_malloc(sizeof(*r),"leafnode");
+       NEW(r);
        r->type=type;
        r->loc.file=config_file;
        r->loc.line=config_lineno;
index 7837abe651365c12e460f4492db4f39da5f825d6..9f32cfdaf5c6ba53d4f37397449043351b97dc51 100644 (file)
@@ -103,7 +103,7 @@ static struct p_node *node(uint32_t type, struct p_node *l, struct p_node *r)
 {
        struct p_node *rv;
 
-       rv=safe_malloc(sizeof(*rv),"p_node");
+       NEW(rv);
        rv->type=type;
        rv->loc.file=config_file;
        rv->loc.line=config_lineno;
diff --git a/dh.c b/dh.c
index c37b5386359294f856fb08eaf156a4c2ca586856..54d3102e00163bebf9b45d581dbcbfee2e32766f 100644 (file)
--- a/dh.c
+++ b/dh.c
@@ -63,7 +63,7 @@ static list_t *dh_apply(closure_t *self, struct cloc loc, dict_t *context,
     string_t p,g;
     item_t *i;
 
-    st=safe_malloc(sizeof(*st),"dh_apply");
+    NEW(st);
     st->cl.description="dh";
     st->cl.type=CL_DH;
     st->cl.apply=NULL;
index 899581f0e0a11bae619c03b8ad1d01fb32b010af..b3cd0a7bf55050c2957e72b341e838bb12e9bca1 100644 (file)
--- a/ipaddr.c
+++ b/ipaddr.c
@@ -15,7 +15,7 @@
 struct subnet_list *subnet_list_new(void)
 {
     struct subnet_list *r;
-    r=safe_malloc(sizeof(*r),"subnet_list_new:list");
+    NEW(r);
     r->entries=0;
     r->alloc=DEFAULT_ALLOC;
     r->list=safe_malloc_ary(sizeof(*r->list),r->alloc,"subnet_list_new:data");
@@ -57,7 +57,7 @@ void subnet_list_append(struct subnet_list *a, uint32_t prefix, int len)
 struct ipset *ipset_new(void)
 {
     struct ipset *r;
-    r=safe_malloc(sizeof(*r),"ipset_new:set");
+    NEW(r);
     r->l=0;
     r->a=DEFAULT_ALLOC;
     r->d=safe_malloc(sizeof(*r->d)*r->a,"ipset_new:data");
diff --git a/log.c b/log.c
index d8b5151132755d417ccb44cccc04a548732a8939..a17032bb3e255ea8db651b7cb5afd8eaa0fc62ec 100644 (file)
--- a/log.c
+++ b/log.c
@@ -266,7 +266,7 @@ struct log_if *init_log(list_t *ll)
        if (cl->type!=CL_LOG) {
            cfgfatal(item->loc,"init_log","closure is not a logger");
        }
-       n=safe_malloc(sizeof(*n),"init_log");
+       NEW(n);
        n->l=cl->interface;
        n->next=l;
        l=n;
@@ -402,7 +402,7 @@ static list_t *logfile_apply(closure_t *self, struct cloc loc, dict_t *context,
        phase.  We should defer writing into the logfile until after we
        become a daemon. */
     
-    st=safe_malloc(sizeof(*st),"logfile_apply");
+    NEW(st);
     st->cl.description="logfile";
     st->cl.type=CL_LOG;
     st->cl.apply=NULL;
@@ -517,7 +517,7 @@ static list_t *syslog_apply(closure_t *self, struct cloc loc, dict_t *context,
     item_t *item;
     string_t facstr;
 
-    st=safe_malloc(sizeof(*st),"syslog_apply");
+    NEW(st);
     st->cl.description="syslog";
     st->cl.type=CL_LOG;
     st->cl.apply=NULL;
@@ -613,7 +613,7 @@ void log_from_fd(int fd, cstring_t prefix, struct log_if *log)
 {
     struct fdlog *st;
 
-    st=safe_malloc(sizeof(*st),"log_from_fd");
+    NEW(st);
     st->log=log;
     st->fd=fd;
     st->prefix=prefix;
diff --git a/md5.c b/md5.c
index 343ad8fc893cdd29bbc208c74b7e044f7499d857..69158911eff29cf3540bcae36951e17736d27c27 100644 (file)
--- a/md5.c
+++ b/md5.c
@@ -241,7 +241,7 @@ static void *md5_init(void)
 {
     struct MD5Context *ctx;
 
-    ctx=safe_malloc(sizeof(*ctx),"md5_init");
+    NEW(ctx);
     MD5Init(ctx);
 
     return ctx;
@@ -278,7 +278,7 @@ void md5_module(dict_t *dict)
     uint8_t digest[16];
     int i;
 
-    st=safe_malloc(sizeof(*st),"md5_module");
+    NEW(st);
     st->cl.description="md5";
     st->cl.type=CL_HASH;
     st->cl.apply=NULL;
index 601686425124cb7d7bb46cb03500f9df75e7c909..e180b1dfad95fb53f4f46e61516ae83440873538 100644 (file)
--- a/netlink.c
+++ b/netlink.c
@@ -1138,7 +1138,7 @@ static closure_t *netlink_inst_create(struct netlink *st,
        return NULL;
     }
 
-    c=safe_malloc(sizeof(*c),"netlink_inst_create");
+    NEW(c);
     c->cl.description=name;
     c->cl.type=CL_NETLINK;
     c->cl.apply=NULL;
@@ -1307,7 +1307,7 @@ static list_t *null_apply(closure_t *self, struct cloc loc, dict_t *context,
     item_t *item;
     dict_t *dict;
 
-    st=safe_malloc(sizeof(*st),"null_apply");
+    NEW(st);
 
     item=list_elem(args,0);
     if (!item || item->type!=t_dict)
index c14dd694d977afe51dd742c9428303890cb4869d..f83625815456648ced0ad0a1781f2610e04a07d4 100644 (file)
--- a/process.c
+++ b/process.c
@@ -45,7 +45,7 @@ pid_t makesubproc(process_entry_fn *entry, process_callback_fn *cb,
     struct child *c;
     pid_t p;
 
-    c=safe_malloc(sizeof(*c),"makesubproc");
+    NEW(c);
     c->desc=desc;
     c->cb=cb;
     c->cst=cst;
@@ -92,7 +92,7 @@ static void sigchld_handler(void *st, int signum)
        if (rv==i->pid) {
            i->finished=True;
            
-           nw=safe_malloc(sizeof(*nw),"sigchld_handler");
+           NEW(nw);
            nw->pid=i->pid;
            nw->cb=i->cb;
            nw->cst=i->cst;
@@ -291,7 +291,7 @@ void request_signal_notification(int signum, signal_notify_fn *notify,
     struct signotify *s;
     sigset_t old;
 
-    s=safe_malloc(sizeof(*s),"request_signal_notification");
+    NEW(s);
     s->signum=signum;
     s->notify=notify;
     s->cst=cst;
index 39a9cb07c78f57183358059b21069743dd6b35e1..0c0f947d03c78cdb84f8a316e18684310aadf1d5 100644 (file)
--- a/random.c
+++ b/random.c
@@ -51,7 +51,7 @@ static list_t *random_apply(closure_t *self, struct cloc loc,
     item_t *arg1, *arg2;
     string_t filename=NULL;
 
-    st=safe_malloc(sizeof(*st),"random_apply");
+    NEW(st);
 
     st->cl.description="randomsource";
     st->cl.type=CL_RANDOMSRC;
index a39e9fcde510dea5e96bf81dcf05aad079ea982d..e9f42f1b88aa83f2a68c609d6636b9a82e5451ca 100644 (file)
@@ -173,7 +173,7 @@ static list_t *adnsresolver_apply(closure_t *self, struct cloc loc,
     item_t *i;
     string_t conf;
 
-    st=safe_malloc(sizeof(*st),"adnsresolver_apply");
+    NEW(st);
     st->cl.description="adns";
     st->cl.type=CL_RESOLVER;
     st->cl.apply=NULL;
diff --git a/rsa.c b/rsa.c
index f7dd69db6f69115e03c94779a2529468b642619f..bdacfe99d120099009f9e24c3452f1e856069630 100644 (file)
--- a/rsa.c
+++ b/rsa.c
@@ -177,7 +177,7 @@ static list_t *rsapub_apply(closure_t *self, struct cloc loc, dict_t *context,
     item_t *i;
     string_t e,n;
 
-    st=safe_malloc(sizeof(*st),"rsapub_apply");
+    NEW(st);
     st->cl.description="rsapub";
     st->cl.type=CL_RSAPUBKEY;
     st->cl.apply=NULL;
@@ -255,7 +255,7 @@ static list_t *rsapriv_apply(closure_t *self, struct cloc loc, dict_t *context,
     MP_INT e,d,iqmp,tmp,tmp2,tmp3;
     bool_t valid;
 
-    st=safe_malloc(sizeof(*st),"rsapriv_apply");
+    NEW(st);
     st->cl.description="rsapriv";
     st->cl.type=CL_RSAPRIVKEY;
     st->cl.apply=NULL;
index 30db8e1878a66065cf97ba6e7d1c0aa0d0d379f2..7aaaef543145411ab27b3f07fca42753f4173fcf 100644 (file)
--- a/secnet.c
+++ b/secnet.c
@@ -235,7 +235,7 @@ struct poll_interest *register_for_poll(void *st, beforepoll_fn *before,
 {
     struct poll_interest *i;
 
-    i=safe_malloc(sizeof(*i),"register_for_poll");
+    NEW(i);
     i->before=before;
     i->after=after;
     i->state=st;
diff --git a/sha1.c b/sha1.c
index a0f26e8be6facdadfed882d1cf4dd65fd6da9523..0202ed3b30e86bf416281d5810631c991497d773 100644 (file)
--- a/sha1.c
+++ b/sha1.c
@@ -288,7 +288,7 @@ static void *sha1_init(void)
 {
     SHA1_CTX *ctx;
 
-    ctx=safe_malloc(sizeof(*ctx),"sha1_init");
+    NEW(ctx);
     SHA1Init(ctx);
 
     return ctx;
@@ -329,7 +329,7 @@ void sha1_module(dict_t *dict)
     uint8_t digest[20];
     int i;
 
-    st=safe_malloc(sizeof(*st),"sha1_module");
+    NEW(st);
     st->cl.description="sha1";
     st->cl.type=CL_HASH;
     st->cl.apply=NULL;
diff --git a/site.c b/site.c
index 1c57a8a66b6296ca305b7efab2d4cf9035838c56..94da06ccafd9b47f2e51d3e60e42589270a66b2d 100644 (file)
--- a/site.c
+++ b/site.c
@@ -1927,7 +1927,7 @@ static list_t *site_apply(closure_t *self, struct cloc loc, dict_t *context,
     dict_t *dict;
     int i;
 
-    st=safe_malloc(sizeof(*st),"site_apply");
+    NEW(st);
 
     st->cl.description="site";
     st->cl.type=CL_SITE;
diff --git a/slip.c b/slip.c
index fad0a7ee394fa2a764e9853129f68cc19dac55b8..a23675253c603fb580c81ae0954b8e7943d1128f 100644 (file)
--- a/slip.c
+++ b/slip.c
@@ -419,7 +419,7 @@ static list_t *userv_apply(closure_t *self, struct cloc loc, dict_t *context,
     item_t *item;
     dict_t *dict;
 
-    st=safe_malloc(sizeof(*st),"userv_apply");
+    NEW(st);
 
     /* First parameter must be a dict */
     item=list_elem(args,0);
index 02cbd4c2bf634bd4393c432b899f55610a7843c0..ebf47028ae3fdfbe4f9b77a2373d199ce6de376a 100644 (file)
@@ -256,7 +256,7 @@ static list_t *transform_apply(closure_t *self, struct cloc loc,
     item_t *item;
     dict_t *dict;
 
-    st=safe_malloc(sizeof(*st),"serpent");
+    NEW(st);
     st->cl.description="serpent-cbc256";
     st->cl.type=CL_TRANSFORM;
     st->cl.apply=NULL;
index d1ff1bedf2c7b7546c918b553fbf2a9d265fd1d3..906d2b30b6c6b15e7a6dcc6dd6feb33716e40ef1 100644 (file)
@@ -258,7 +258,7 @@ static list_t *transform_apply(closure_t *self, struct cloc loc,
     item_t *item;
     dict_t *dict;
 
-    st=safe_malloc(sizeof(*st),"eax-serpent");
+    NEW(st);
     st->cl.description="eax-serpent";
     st->cl.type=CL_TRANSFORM;
     st->cl.apply=NULL;
diff --git a/tun.c b/tun.c
index b3c69a2351e0fea272c4fef404c50d585b8159d5..d5e0e9e985e31eb615e0bcf5655d7c37f2116aab 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -456,7 +456,7 @@ static list_t *tun_create(closure_t *self, struct cloc loc, dict_t *context,
     dict_t *dict;
     string_t flavour,type;
 
-    st=safe_malloc(sizeof(*st),"tun_apply");
+    NEW(st);
 
     /* First parameter must be a dict */
     item=list_elem(args,0);
diff --git a/util.c b/util.c
index 803098cb2b81183eae8161a963ff27d7c0c5c8d6..1d05822f5dfb53dcb80acefbd3d1575deb2d1138 100644 (file)
--- a/util.c
+++ b/util.c
@@ -240,7 +240,7 @@ bool_t add_hook(uint32_t phase, hook_fn *fn, void *state)
 {
     struct phase_hook *h;
 
-    h=safe_malloc(sizeof(*h),"add_hook");
+    NEW(h);
     h->fn=fn;
     h->state=state;
     LIST_INSERT_HEAD(&hooks[phase],h,entry);
@@ -398,7 +398,7 @@ static list_t *buffer_apply(closure_t *self, struct cloc loc, dict_t *context,
     bool_t lockdown=False;
     uint32_t len=DEFAULT_BUFFER_SIZE;
     
-    st=safe_malloc(sizeof(*st),"buffer_apply");
+    NEW(st);
     st->cl.description="buffer";
     st->cl.type=CL_BUFFER;
     st->cl.apply=NULL;