chiark / gitweb /
subnet_to_string: Do not allocate
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 19 Sep 2014 22:37:58 +0000 (23:37 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Sep 2014 12:36:50 +0000 (13:36 +0100)
None of the three call sites want to keep the value for any length of
time - they just use it right away.  Replace the allocation with a use
of the round-robin buffers from ipaddr_getbuf, and remove the frees at
the call sites.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
ipaddr.c
netlink.c
slip.c

index 6d0b02ad0b1f61c18c845de917b448985d972891..d23317c90dd1308b6d5a4c53fec0ec89bcdbd217 100644 (file)
--- a/ipaddr.c
+++ b/ipaddr.c
@@ -358,7 +358,7 @@ string_t subnet_to_string(struct subnet sn)
     uint8_t a,b,c,d;
     string_t s;
 
-    s=safe_malloc(19,"subnet_to_string");
+    s=ipaddr_getbuf();
     a=addr>>24;
     b=addr>>16;
     c=addr>>8;
index b54327bbb4aeb0efa94548a6b63ca98c89bd7077..189c0bb7aeb8662e52f5f39086e98a21e088ad9b 100644 (file)
--- a/netlink.c
+++ b/netlink.c
@@ -976,7 +976,6 @@ static void netlink_output_subnets(struct netlink *st, uint32_t loglevel,
     for (i=0; i<snets->entries; i++) {
        net=subnet_to_string(snets->list[i]);
        Message(loglevel,"%s ",net);
-       free(net);
     }
 }
 
@@ -1014,7 +1013,6 @@ static void netlink_dump_routes(struct netlink *st, bool_t requested)
        for (i=0; i<st->subnets->entries; i++) {
            net=subnet_to_string(st->subnets->list[i]);
            Message(c,"%s ",net);
-           free(net);
        }
        if (i>0)
            Message(c,"-> host (use %d)\n",st->outcount);
diff --git a/slip.c b/slip.c
index 891b2686bdf4c1a4b9612a9d167496a6bcf40686..d8b32d8dbda79b5ad8ad4432be2adb4d3a166a10 100644 (file)
--- a/slip.c
+++ b/slip.c
@@ -313,7 +313,6 @@ static void userv_invoke_userv(struct userv *st)
        s=subnet_to_string(snets->list[i]);
        strcat(nets,s);
        strcat(nets,",");
-       free(s);
     }
     nets[strlen(nets)-1]=0;
     subnet_list_free(snets);