From 70887982887b300b4783318c858914482580831d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 19 Sep 2014 23:37:58 +0100 Subject: [PATCH] subnet_to_string: Do not allocate 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 --- ipaddr.c | 2 +- netlink.c | 2 -- slip.c | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/ipaddr.c b/ipaddr.c index 6d0b02a..d23317c 100644 --- 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; diff --git a/netlink.c b/netlink.c index 07c1468..e197e80 100644 --- a/netlink.c +++ b/netlink.c @@ -976,7 +976,6 @@ static void netlink_output_subnets(struct netlink *st, uint32_t loglevel, for (i=0; ientries; 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; isubnets->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 --- 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); -- 2.30.2