diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2017-02-04 11:56:14 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2017-02-06 17:26:28 +0100 |
commit | 8fd19eefa46b313673d6ba2a0194a68674ef5ea9 (patch) | |
tree | 569da73381afb80fe8eb70d1183fbac0339da4ef /astraceroute.c | |
parent | 1e1383fea55fb35cec96a352da93c2a31d9e897c (diff) |
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 <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'astraceroute.c')
-rw-r--r-- | astraceroute.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/astraceroute.c b/astraceroute.c index 98b97e4..ca47ba0 100644 --- a/astraceroute.c +++ b/astraceroute.c @@ -457,7 +457,8 @@ static void handle_ipv4(uint8_t *packet, size_t len __maybe_unused, struct iphdr *iph = (struct iphdr *) packet; struct sockaddr_in sd; struct hostent *hent; - const char *as, *country, *city; + const char *as, *country; + char *city; memset(hbuff, 0, sizeof(hbuff)); memset(&sd, 0, sizeof(sd)); @@ -489,6 +490,8 @@ static void handle_ipv4(uint8_t *packet, size_t len __maybe_unused, } if (latitude) printf(" (%f/%f)", geoip4_latitude(&sd), geoip4_longitude(&sd)); + + free(city); } static int check_ipv6(uint8_t *packet, size_t len, int ttl __maybe_unused, @@ -524,7 +527,8 @@ static void handle_ipv6(uint8_t *packet, size_t len __maybe_unused, struct ip6_hdr *ip6h = (struct ip6_hdr *) packet; struct sockaddr_in6 sd; struct hostent *hent; - const char *as, *country, *city; + const char *as, *country; + char *city; memset(hbuff, 0, sizeof(hbuff)); memset(&sd, 0, sizeof(sd)); @@ -556,6 +560,8 @@ static void handle_ipv6(uint8_t *packet, size_t len __maybe_unused, } if (latitude) printf(" (%f/%f)", geoip6_latitude(&sd), geoip6_longitude(&sd)); + + free(city); } static void show_trace_info(struct ctx *ctx, const struct sockaddr_storage *ss, |