[PATCH 01/31] subnet_to_string: Do not allocate
Ian Jackson
ijackson at chiark.greenend.org.uk
Sat Sep 20 01:31:56 BST 2014
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 at chiark.greenend.org.uk>
---
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 b54327b..189c0bb 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; 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 17a9099..94ce4d6 100644
--- a/slip.c
+++ b/slip.c
@@ -315,7 +315,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);
--
1.7.10.4
More information about the sgo-software-discuss
mailing list