diff options
author | Michael Mann <mmann78@netscape.net> | 2015-01-17 20:34:35 -0500 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2015-01-18 04:14:03 +0000 |
commit | 403be722cee0aa78b6c57b7e61c35d2d59780713 (patch) | |
tree | d7798c6683f95a6a6e0a8cb952f4b3165293c17c /epan | |
parent | 86726f404a60003585d6a5f64f908b091bcac099 (diff) |
Remove emem from GeoIP
Change-Id: Ifa96dc38a277b86c28f762489251dcc595afae67
Reviewed-on: https://code.wireshark.org/review/6603
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dissectors/packet-ip.c | 3 | ||||
-rw-r--r-- | epan/dissectors/packet-ipv6.c | 3 | ||||
-rw-r--r-- | epan/geoip_db.c | 79 | ||||
-rw-r--r-- | epan/geoip_db.h | 8 |
4 files changed, 64 insertions, 29 deletions
diff --git a/epan/dissectors/packet-ip.c b/epan/dissectors/packet-ip.c index 3b8953234b..c256852b55 100644 --- a/epan/dissectors/packet-ip.c +++ b/epan/dissectors/packet-ip.c @@ -608,7 +608,7 @@ add_geoip_info_entry(proto_tree *geoip_info_tree, proto_item *geoip_info_item, t guint dbnum; for (dbnum = 0; dbnum < num_dbs; dbnum++) { - const char *geoip_str = geoip_db_lookup_ipv4(dbnum, ip, NULL); + char *geoip_str = geoip_db_lookup_ipv4(dbnum, ip, NULL); int db_type = geoip_db_type(dbnum); int geoip_hf, geoip_local_hf; @@ -674,6 +674,7 @@ add_geoip_info_entry(proto_tree *geoip_info_tree, proto_item *geoip_info_item, t item_cnt++; proto_item_append_text(geoip_info_item, "%s%s", plurality(item_cnt, "", ", "), geoip_str); + wmem_free(NULL, geoip_str); } } diff --git a/epan/dissectors/packet-ipv6.c b/epan/dissectors/packet-ipv6.c index e38a848448..409e1a0680 100644 --- a/epan/dissectors/packet-ipv6.c +++ b/epan/dissectors/packet-ipv6.c @@ -644,7 +644,7 @@ add_geoip_info_entry(proto_tree *geoip_info_tree, proto_item *geoip_info_item, t guint dbnum; for (dbnum = 0; dbnum < num_dbs; dbnum++) { - const char *geoip_str = geoip_db_lookup_ipv6(dbnum, *ip, NULL); + char *geoip_str = geoip_db_lookup_ipv6(dbnum, *ip, NULL); int db_type = geoip_db_type(dbnum); int geoip_hf, geoip_local_hf; @@ -708,6 +708,7 @@ add_geoip_info_entry(proto_tree *geoip_info_tree, proto_item *geoip_info_item, t item_cnt++; proto_item_append_text(geoip_info_item, "%s%s", plurality(item_cnt, "", ", "), geoip_str); + wmem_free(NULL, geoip_str); } } diff --git a/epan/geoip_db.c b/epan/geoip_db.c index 3b1ce0cbf2..f94ba7c8c7 100644 --- a/epan/geoip_db.c +++ b/epan/geoip_db.c @@ -290,30 +290,33 @@ geoip_db_lookup_latlon4(guint32 addr, float *lat, float *lon) { */ /* Ensure that a given db value is UTF-8 */ -static const char * +static char * db_val_to_utf_8(const char *val, GeoIP *gi) { if (GeoIP_charset(gi) == GEOIP_CHARSET_ISO_8859_1) { char *utf8_val; utf8_val = g_convert(val, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); if (utf8_val) { - char *ret_val = ep_strdup(utf8_val); + char *ret_val = wmem_strdup(NULL, utf8_val); g_free(utf8_val); return ret_val; } } - return val; + return wmem_strdup(NULL, val); } -const char * +char * geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found) { GeoIP *gi; GeoIPRecord *gir; - const char *raw_val, *ret = not_found; - char *val; + const char *raw_val; + char *val, *ret = NULL; if (dbnum > geoip_db_num_dbs()) { - return ret; + if (not_found == NULL) + return NULL; + + return wmem_strdup(NULL, not_found); } gi = g_array_index(geoip_dat_arr, GeoIP *, dbnum); if (gi) { @@ -329,8 +332,9 @@ geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found) { case GEOIP_CITY_EDITION_REV1: gir = GeoIP_record_by_ipnum(gi, addr); if (gir && gir->city && gir->region) { - val = ep_strdup_printf("%s, %s", gir->city, gir->region); + val = wmem_strdup_printf(NULL, "%s, %s", gir->city, gir->region); ret = db_val_to_utf_8(val, gi); + wmem_free(NULL, val); } else if (gir && gir->city) { ret = db_val_to_utf_8(gir->city, gi); } @@ -351,7 +355,7 @@ geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found) { float lon; char *c; if(geoip_db_lookup_latlon4(addr, &lat, &lon) == 0) { - val = ep_strdup_printf("%f", lat); + val = wmem_strdup_printf(NULL, "%f", lat); c = strchr(val, ','); if (c != NULL) *c = '.'; ret = val; @@ -365,7 +369,7 @@ geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found) { float lon; char *c; if(geoip_db_lookup_latlon4(addr, &lat, &lon) == 0) { - val = ep_strdup_printf("%f", lon); + val = wmem_strdup_printf(NULL, "%f", lon); c = strchr(val, ','); if (c != NULL) *c = '.'; ret = val; @@ -377,6 +381,14 @@ geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found) { break; } } + + if (ret == NULL) { + if (not_found == NULL) + return NULL; + + return wmem_strdup(NULL, not_found); + } + return ret; } @@ -417,17 +429,20 @@ geoip_db_lookup_latlon6(geoipv6_t addr _U_, float *lat _U_, float *lon _U_) { } #endif /* NUM_DB_TYPES */ -const char * +char * geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found) { GeoIP *gi; geoipv6_t gaddr; - const char *raw_val, *ret = not_found; - char *val; + const char *raw_val; + char *val, *ret = NULL; #if NUM_DB_TYPES > 31 GeoIPRecord *gir; #endif if (dbnum > geoip_db_num_dbs()) { - return ret; + if (not_found == NULL) + return NULL; + + return wmem_strdup(NULL, not_found); } memcpy(&gaddr, &addr, sizeof(addr)); @@ -447,8 +462,9 @@ geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found) case GEOIP_CITY_EDITION_REV1_V6: gir = GeoIP_record_by_ipnum_v6(gi, gaddr); if (gir && gir->city && gir->region) { - val = ep_strdup_printf("%s, %s", gir->city, gir->region); + val = wmem_strdup_printf(NULL, "%s, %s", gir->city, gir->region); ret = db_val_to_utf_8(val, gi); + wmem_free(NULL, val); } else if (gir && gir->city) { ret = db_val_to_utf_8(gir->city, gi); } @@ -470,7 +486,7 @@ geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found) float lon; char *c; if(geoip_db_lookup_latlon6(gaddr, &lat, &lon) == 0) { - val = ep_strdup_printf("%f", lat); + val = wmem_strdup_printf(NULL, "%f", lat); c = strchr(val, ','); if (c != NULL) *c = '.'; ret = val; @@ -484,7 +500,7 @@ geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found) float lon; char *c; if(geoip_db_lookup_latlon6(gaddr, &lat, &lon) == 0) { - val = ep_strdup_printf("%f", lon); + val = wmem_strdup_printf(NULL, "%f", lon); c = strchr(val, ','); if (c != NULL) *c = '.'; ret = val; @@ -496,14 +512,25 @@ geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found) break; } } + + if (ret == NULL) { + if (not_found == NULL) + return NULL; + + return wmem_strdup(NULL, not_found); + } + return ret; } #else /* HAVE_GEOIP_V6 */ -const char * +char * geoip_db_lookup_ipv6(guint dbnum _U_, struct e_in6_addr addr _U_, const char *not_found) { - return not_found; + if (not_found == NULL) + return NULL; + + return wmem_strdup(NULL, not_found); } #endif /* HAVE_GEOIP_V6 */ @@ -548,14 +575,20 @@ geoip_db_type(guint dbnum _U_) { return -1; } -const char * +char * geoip_db_lookup_ipv4(guint dbnum _U_, guint32 addr _U_, const char *not_found) { - return not_found; + if (not_found == NULL) + return NULL; + + return wmem_strdup(NULL, not_found); } -const char * +char * geoip_db_lookup_ipv6(guint dbnum _U_, guint32 addr _U_, const char *not_found) { - return not_found; + if (not_found == NULL) + return NULL; + + return wmem_strdup(NULL, not_found); } gchar * diff --git a/epan/geoip_db.h b/epan/geoip_db.h index 346b50b602..568a1243aa 100644 --- a/epan/geoip_db.h +++ b/epan/geoip_db.h @@ -74,9 +74,9 @@ WS_DLL_PUBLIC int geoip_db_type(guint dbnum); * @param addr IPv4 address to look up * @param not_found The string to return if the lookup fails. May be NULL. * - * @return The database entry if found, else not_found. Return value must not be freed. + * @return The database entry if found, else not_found. Return value must be freed with wmem_free. */ -WS_DLL_PUBLIC const char *geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found); +WS_DLL_PUBLIC char *geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const char *not_found); /** * Look up an IPv6 address in a database @@ -85,9 +85,9 @@ WS_DLL_PUBLIC const char *geoip_db_lookup_ipv4(guint dbnum, guint32 addr, const * @param addr IPv6 address to look up * @param not_found The string to return if the lookup fails. May be NULL. * - * @return The database entry if found, else not_found. Return value must not be freed. + * @return The database entry if found, else not_found. Return value must be freed with wmem_free. */ -WS_DLL_PUBLIC const char *geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found); +WS_DLL_PUBLIC char *geoip_db_lookup_ipv6(guint dbnum, struct e_in6_addr addr, const char *not_found); /** * Get all configured paths |