aboutsummaryrefslogtreecommitdiffstats
path: root/extcap_parser.c
diff options
context:
space:
mode:
authorMikael Kanstrup <mikael.kanstrup@gmail.com>2016-09-08 14:26:58 +0200
committerPeter Wu <peter@lekensteyn.nl>2016-09-12 12:13:41 +0000
commitc64762d33c3a9cbc4af4040284534b440d12b210 (patch)
treecd1f29e92e31ba93e19281575a1b8d4eeda7fd51 /extcap_parser.c
parente079862fad331cba874717ec1d0af9e35ba438b5 (diff)
extcap: Fix misc memory leaks triggered by network interface changes
Valgrind reports plenty of misc memory leaks in extcap after the network interface list has changed or is refreshed. Errors can be seen by starting Wireshark with Valgrind's memcheck tool and bringing a network interface up and down a few times with: ifconfig eth0 up ifconfig eth0 down Change-Id: I90f53847071854b7d02facb39b7a380732de79b4 Reviewed-on: https://code.wireshark.org/review/17606 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'extcap_parser.c')
-rw-r--r--extcap_parser.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/extcap_parser.c b/extcap_parser.c
index f9e2c856ea..0fd4c8f9ac 100644
--- a/extcap_parser.c
+++ b/extcap_parser.c
@@ -118,7 +118,6 @@ static extcap_token_sentence *extcap_tokenize_sentence(const gchar *s) {
extcap_token_sentence *rs = g_new0(extcap_token_sentence, 1);
rs->sentence = NULL;
- rs->param_list = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
/* Regex for catching just the allowed values for sentences */
if ( ( regex = g_regex_new ( "^[\\t| ]*(arg|value|interface|extcap|dlt)(?=[\\t| ]+\\{)",
@@ -137,6 +136,8 @@ static extcap_token_sentence *extcap_tokenize_sentence(const gchar *s) {
return NULL;
}
+ rs->param_list = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
+
/* Capture the argument and the value of the list. This will ensure,
* that regex patterns given to {validation=} are parsed correctly,
* as long as }{ does not occur within the pattern */
@@ -150,7 +151,7 @@ static extcap_token_sentence *extcap_tokenize_sentence(const gchar *s) {
if ( arg == NULL )
break;
- param_value = g_strdup(g_match_info_fetch ( match_info, 2 ));
+ param_value = g_match_info_fetch ( match_info, 2 );
if (g_ascii_strcasecmp(arg, "number") == 0) {
param_type = EXTCAP_PARAM_ARGNUM;
@@ -197,6 +198,7 @@ static extcap_token_sentence *extcap_tokenize_sentence(const gchar *s) {
g_hash_table_insert(rs->param_list, ENUM_KEY(param_type), param_value);
g_match_info_next(match_info, &error);
+ g_free(arg);
}
g_match_info_free(match_info);
g_regex_unref(regex);
@@ -260,15 +262,12 @@ void extcap_free_arg(extcap_arg *a) {
extcap_free_complex(a->default_complex);
g_list_foreach(a->values, (GFunc) extcap_free_valuelist, NULL);
-}
-
-static void extcap_free_arg_list_cb(gpointer listentry, gpointer data _U_) {
- if (listentry != NULL)
- extcap_free_arg((extcap_arg *) listentry);
+ g_list_free(a->values);
+ g_free(a);
}
void extcap_free_arg_list(GList *a) {
- g_list_foreach(a, extcap_free_arg_list_cb, NULL);
+ g_list_foreach(a, (GFunc)extcap_free_arg, NULL);
g_list_free(a);
}
@@ -279,12 +278,22 @@ static gint glist_find_numbered_arg(gconstpointer listelem, gconstpointer needle
}
static void extcap_free_tokenized_sentence(gpointer s, gpointer user_data _U_) {
+ extcap_token_sentence *t = (extcap_token_sentence *)s;
- if (s == NULL)
+ if (t == NULL)
+ return;
+
+ g_free(t->sentence);
+ g_hash_table_destroy(t->param_list);
+ g_free(t);
+}
+
+static void extcap_free_tokenized_sentences(GList *sentences) {
+ if (sentences == NULL)
return;
- g_free(((extcap_token_sentence *)s)->sentence);
- g_hash_table_destroy(((extcap_token_sentence *)s)->param_list);
+ g_list_foreach(sentences, extcap_free_tokenized_sentence, NULL);
+ g_list_free(sentences);
}
static extcap_arg *extcap_parse_arg_sentence(GList * args, extcap_token_sentence *s) {
@@ -530,7 +539,7 @@ GList * extcap_parse_args(gchar *output) {
walker = g_list_next(walker);
}
- g_list_foreach(temp, extcap_free_tokenized_sentence, NULL);
+ extcap_free_tokenized_sentences(temp);
return result;
}
@@ -603,7 +612,7 @@ GList * extcap_parse_interfaces(gchar *output) {
walker = g_list_next(walker);
}
- g_list_foreach(tokens, extcap_free_tokenized_sentence, NULL);
+ extcap_free_tokenized_sentences(tokens);
return result;
}
@@ -681,7 +690,7 @@ GList * extcap_parse_dlts(gchar *output) {
walker = g_list_next(walker);
}
- g_list_foreach(temp, extcap_free_tokenized_sentence, NULL);
+ extcap_free_tokenized_sentences(temp);
return result;
}