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 6d0b02a..d23317c 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 b54327b..189c0bb 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 891b268..d8b32d8 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);