summaryrefslogtreecommitdiff
path: root/proto_ipv6.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2017-02-04 11:56:14 +0200
committerTobias Klauser <tklauser@distanz.ch>2017-02-06 17:26:28 +0100
commit8fd19eefa46b313673d6ba2a0194a68674ef5ea9 (patch)
tree569da73381afb80fe8eb70d1183fbac0339da4ef /proto_ipv6.c
parent1e1383fea55fb35cec96a352da93c2a31d9e897c (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 'proto_ipv6.c')
-rw-r--r--proto_ipv6.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/proto_ipv6.c b/proto_ipv6.c
index ba3f6c8..e3e8f68 100644
--- a/proto_ipv6.c
+++ b/proto_ipv6.c
@@ -27,7 +27,8 @@ void ipv6(struct pkt_buff *pkt)
char dst_ip[INET6_ADDRSTRLEN];
struct ipv6hdr *ip = (struct ipv6hdr *) pkt_pull(pkt, sizeof(*ip));
struct sockaddr_in6 sas, sad;
- const char *city, *region, *country;
+ char *city, *region;
+ const char *country;
if (ip == NULL)
return;
@@ -62,20 +63,28 @@ void ipv6(struct pkt_buff *pkt)
tprintf("\t[ Geo (");
if ((country = geoip6_country_name(&sas))) {
tprintf("%s", country);
- if ((region = geoip6_region_name(&sas)))
+ if ((region = geoip6_region_name(&sas))) {
tprintf(" / %s", region);
- if ((city = geoip6_city_name(&sas)))
+ xfree(region);
+ }
+ if ((city = geoip6_city_name(&sas))) {
tprintf(" / %s", city);
+ xfree(city);
+ }
} else {
tprintf("local");
}
tprintf(" => ");
if ((country = geoip6_country_name(&sad))) {
tprintf("%s", country);
- if ((region = geoip6_region_name(&sad)))
+ if ((region = geoip6_region_name(&sad))) {
tprintf(" / %s", region);
- if ((city = geoip6_city_name(&sad)))
+ xfree(region);
+ }
+ if ((city = geoip6_city_name(&sad))) {
tprintf(" / %s", city);
+ xfree(city);
+ }
} else {
tprintf("local");
}