diff options
author | Michael Mann <mmann78@netscape.net> | 2015-01-16 23:11:49 -0500 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2015-01-18 00:28:53 +0000 |
commit | 86726f404a60003585d6a5f64f908b091bcac099 (patch) | |
tree | 91fa7b0b3c2b80d0cb9efa8cee25d95d5a1a2a4e /epan/dfilter | |
parent | 0ad15f88ccf434e8210ca64bc99ceeb24a943eb3 (diff) |
Trim down the use of ep_ memory in the display filter code.
Couldn't quite eliminate it completely, but it's much improved. Need to figure out where/when to free dfilter_error_msg.
Change-Id: I10216e9546d38e83f69991ded8ec0b3fc8472035
Reviewed-on: https://code.wireshark.org/review/6591
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/dfilter')
-rw-r--r-- | epan/dfilter/dfilter-macro.c | 40 | ||||
-rw-r--r-- | epan/dfilter/dfilter-macro.h | 2 | ||||
-rw-r--r-- | epan/dfilter/dfilter.c | 8 | ||||
-rw-r--r-- | epan/dfilter/dfunctions.c | 3 |
4 files changed, 31 insertions, 22 deletions
diff --git a/epan/dfilter/dfilter-macro.c b/epan/dfilter/dfilter-macro.c index fef1f2c561..578bac60c6 100644 --- a/epan/dfilter/dfilter-macro.c +++ b/epan/dfilter/dfilter-macro.c @@ -110,7 +110,7 @@ void dfilter_macro_save(const gchar* filename, gchar** error) { FILE* f = ws_fopen(filename,"w"); if (!f) { - *error = ep_strdup_printf("Could not open file: '%s', error: %s\n", filename, g_strerror(errno) ); + *error = wmem_strdup_printf(NULL, "Could not open file: '%s', error: %s\n", filename, g_strerror(errno) ); return; } @@ -146,14 +146,14 @@ void dfilter_macro_dump(void) { #endif } -static const gchar* dfilter_macro_resolve(gchar* name, gchar** args, const gchar** error) { +static gchar* dfilter_macro_resolve(gchar* name, gchar** args, gchar** error) { GString* text; int argc = 0; dfilter_macro_t* m = NULL; fvt_cache_entry_t* e; int* arg_pos_p; gchar** parts; - const gchar* ret; + gchar* ret; guint i; for (i = 0; i < num_macros; i++) { @@ -168,13 +168,13 @@ static const gchar* dfilter_macro_resolve(gchar* name, gchar** args, const gchar if (fvt_cache && (e = (fvt_cache_entry_t *)g_hash_table_lookup(fvt_cache,name)) != NULL) { if(e->usable) { - return e->repr; + return wmem_strdup(NULL, e->repr); } else { - *error = ep_strdup_printf("macro '%s' is unusable", name); + *error = wmem_strdup_printf(NULL, "macro '%s' is unusable", name); return NULL; } } else { - *error = ep_strdup_printf("macro '%s' does not exist", name); + *error = wmem_strdup_printf(NULL, "macro '%s' does not exist", name); return NULL; } } @@ -186,7 +186,7 @@ static const gchar* dfilter_macro_resolve(gchar* name, gchar** args, const gchar } if (argc != m->argc) { - *error = ep_strdup_printf("wrong number of arguments for macro '%s', expecting %d instead of %d", + *error = wmem_strdup_printf(NULL, "wrong number of arguments for macro '%s', expecting %d instead of %d", name, m->argc, argc); return NULL; } @@ -204,7 +204,7 @@ static const gchar* dfilter_macro_resolve(gchar* name, gchar** args, const gchar } } - ret = ep_strdup(text->str); + ret = wmem_strdup(NULL, text->str); g_string_free(text,TRUE); @@ -212,7 +212,7 @@ static const gchar* dfilter_macro_resolve(gchar* name, gchar** args, const gchar } -static const gchar* dfilter_macro_apply_recurse(const gchar* text, guint depth, const gchar** error) { +static const gchar* dfilter_macro_apply_recurse(const gchar* text, guint depth, gchar** error) { enum { OUTSIDE, STARTING, NAME, ARGS } state = OUTSIDE; GString* out; GString* name = NULL; @@ -223,7 +223,7 @@ static const gchar* dfilter_macro_apply_recurse(const gchar* text, guint depth, gboolean changed = FALSE; if ( depth > 31) { - *error = "too much nesting in macros"; + *error = wmem_strdup(NULL, "too much nesting in macros"); return NULL; } @@ -290,7 +290,7 @@ static const gchar* dfilter_macro_apply_recurse(const gchar* text, guint depth, } else if ( c == ':') { state = ARGS; } else if ( c == '}') { - const gchar* resolved; + gchar* resolved; g_ptr_array_add(args,NULL); @@ -300,22 +300,23 @@ static const gchar* dfilter_macro_apply_recurse(const gchar* text, guint depth, changed = TRUE; g_string_append(out,resolved); + wmem_free(NULL, resolved); FREE_ALL(); state = OUTSIDE; } else if ( c == '\0') { - *error = "end of filter in the middle of a macro expression"; + *error = wmem_strdup(NULL, "end of filter in the middle of a macro expression"); goto on_error; } else { - *error = "invalid char in macro name"; + *error = wmem_strdup(NULL, "invalid char in macro name"); goto on_error; } break; } case ARGS: { switch(c) { case '\0': { - *error = "end of filter in the middle of a macro expression"; + *error = wmem_strdup(NULL, "end of filter in the middle of a macro expression"); goto on_error; } case ';': { g_ptr_array_add(args,g_string_free(arg,FALSE)); @@ -328,14 +329,14 @@ static const gchar* dfilter_macro_apply_recurse(const gchar* text, guint depth, g_string_append_c(arg,c); break; } else { - *error = "end of filter in the middle of a macro expression"; + *error = wmem_strdup(NULL, "end of filter in the middle of a macro expression"); goto on_error; } } default: { g_string_append_c(arg,c); break; } case '}': { - const gchar* resolved; + gchar* resolved; g_ptr_array_add(args,g_string_free(arg,FALSE)); g_ptr_array_add(args,NULL); @@ -347,6 +348,7 @@ static const gchar* dfilter_macro_apply_recurse(const gchar* text, guint depth, changed = TRUE; g_string_append(out,resolved); + wmem_free(NULL, resolved); FREE_ALL(); @@ -368,7 +370,7 @@ finish: g_string_free(out,TRUE); return (*error) ? NULL : resolved; } else { - const gchar* out_str = ep_strdup(out->str); + const gchar* out_str = wmem_strdup(NULL, out->str); g_string_free(out,TRUE); return out_str; } @@ -376,13 +378,13 @@ finish: on_error: { FREE_ALL(); - if (! *error) *error = "unknown error in macro expression"; + if (! *error) *error = wmem_strdup(NULL, "unknown error in macro expression"); g_string_free(out,TRUE); return NULL; } } -const gchar* dfilter_macro_apply(const gchar* text, const gchar** error) { +const gchar* dfilter_macro_apply(const gchar* text, gchar** error) { return dfilter_macro_apply_recurse(text, 0, error); } diff --git a/epan/dfilter/dfilter-macro.h b/epan/dfilter/dfilter-macro.h index eda1cfc050..68462529ac 100644 --- a/epan/dfilter/dfilter-macro.h +++ b/epan/dfilter/dfilter-macro.h @@ -50,7 +50,7 @@ void dfilter_macro_save(const gchar*, gchar**); void dfilter_macro_dump(void); /* applies all macros to the given text and returns the resulting string or NULL on failure */ -const gchar* dfilter_macro_apply(const gchar* text, const gchar** error); +const gchar* dfilter_macro_apply(const gchar* text, gchar** error); void dfilter_macro_init(void); diff --git a/epan/dfilter/dfilter.c b/epan/dfilter/dfilter.c index 96c13c2115..8e21d30853 100644 --- a/epan/dfilter/dfilter.c +++ b/epan/dfilter/dfilter.c @@ -216,6 +216,7 @@ dfilter_compile(const gchar *text, dfilter_t **dfp) guint i; /* XXX, GHashTable */ GPtrArray *deprecated; + gchar *temp_error_msg; g_assert(dfp); @@ -226,7 +227,10 @@ dfilter_compile(const gchar *text, dfilter_t **dfp) dfilter_error_msg = NULL; - if ( !( text = dfilter_macro_apply(text, &dfilter_error_msg) ) ) { + if ( !( text = dfilter_macro_apply(text, &temp_error_msg) ) ) { + /* Move the ep_ allocation up a layer */ + dfilter_error_msg = ep_strdup(temp_error_msg); + wmem_free(NULL, temp_error_msg); return FALSE; } @@ -350,6 +354,7 @@ dfilter_compile(const gchar *text, dfilter_t **dfp) } /* SUCCESS */ dfwork_free(dfw); + wmem_free(NULL, (char*)text); return TRUE; FAILURE: @@ -362,6 +367,7 @@ FAILURE: } g_ptr_array_free(deprecated, TRUE); dfilter_fail("Unable to parse filter string \"%s\".", text); + wmem_free(NULL, (char*)text); *dfp = NULL; return FALSE; diff --git a/epan/dfilter/dfunctions.c b/epan/dfilter/dfunctions.c index 0ce74faaae..6394a1e482 100644 --- a/epan/dfilter/dfunctions.c +++ b/epan/dfilter/dfunctions.c @@ -46,7 +46,7 @@ string_walk(GList* arg1list, GList **retval, gchar(*conv_func)(gchar)) arg_fvalue = (fvalue_t *)arg1->data; /* XXX - it would be nice to handle FT_TVBUFF, too */ if (IS_FT_STRING(fvalue_type_ftenum(arg_fvalue))) { - s = (char *)ep_strdup((gchar *)fvalue_get(arg_fvalue)); + s = (char *)wmem_strdup(NULL, (gchar *)fvalue_get(arg_fvalue)); for (c = s; *c; c++) { /**c = g_ascii_tolower(*c);*/ *c = conv_func(*c); @@ -54,6 +54,7 @@ string_walk(GList* arg1list, GList **retval, gchar(*conv_func)(gchar)) new_ft_string = fvalue_new(FT_STRING); fvalue_set_string(new_ft_string, s); + wmem_free(NULL, s); *retval = g_list_append(*retval, new_ft_string); } arg1 = arg1->next; |