From 8fd19eefa46b313673d6ba2a0194a68674ef5ea9 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Sat, 4 Feb 2017 11:56:14 +0200 Subject: geoip: Fix memory leak when using GeoIPRecord GeoIP_record_by_ipnum{,_v6} returns allocated pointer to GeoIPRecord with allocated city, region & postal_code which is not freed after the call. Fixed by xstrdup-ing required GeoIPRecord member (city/region) and after calling GeoIPRecord_delete to free the geoip record. Of course it is needed to also free obtained city/region in netsniff-ng, astraceroute & flowtop tools. Fixes #169 Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- proto_ipv4.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'proto_ipv4.c') diff --git a/proto_ipv4.c b/proto_ipv4.c index edce915..e2d22d8 100644 --- a/proto_ipv4.c +++ b/proto_ipv4.c @@ -40,7 +40,8 @@ static void ipv4(struct pkt_buff *pkt) uint8_t *opt, *trailer; unsigned int trailer_len = 0; ssize_t opts_len, opt_len; - const char *city, *region, *country; + const char *country; + char *city, *region; if (!ip) return; @@ -101,20 +102,28 @@ static void ipv4(struct pkt_buff *pkt) tprintf("\t[ Geo ("); if ((country = geoip4_country_name(&sas))) { tprintf("%s", country); - if ((region = geoip4_region_name(&sas))) + if ((region = geoip4_region_name(&sas))) { tprintf(" / %s", region); - if ((city = geoip4_city_name(&sas))) + xfree(region); + } + if ((city = geoip4_city_name(&sas))) { tprintf(" / %s", city); + xfree(city); + } } else { tprintf("local"); } tprintf(" => "); if ((country = geoip4_country_name(&sad))) { tprintf("%s", country); - if ((region = geoip4_region_name(&sad))) + if ((region = geoip4_region_name(&sad))) { tprintf(" / %s", region); - if ((city = geoip4_city_name(&sad))) + xfree(region); + } + if ((city = geoip4_city_name(&sad))) { tprintf(" / %s", city); + xfree(city); + } } else { tprintf("local"); } -- cgit v1.2.3-54-g00ecf