summaryrefslogtreecommitdiff
path: root/proto_ipv4.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_ipv4.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_ipv4.c')
-rw-r--r--proto_ipv4.c19
1 files changed, 14 insertions, 5 deletions
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");
}