summaryrefslogtreecommitdiff
path: root/epan
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2016-05-10 16:04:14 -0400
committerMichael Mann <mmann78@netscape.net>2016-05-10 22:49:08 +0000
commit1dccd1ee072722fbe6d5e1a9d726a7e87d191f76 (patch)
tree4d4059e0eead7303c6d7420a3828332d26bd79fa /epan
parent931603c4b84a5e69e94e3bfd3c84332e664062ab (diff)
downloadwireshark-1dccd1ee072722fbe6d5e1a9d726a7e87d191f76.tar.gz
Have fvalue_to_string_repr always return an (wmem) allocated buffer.
Previous patches converted all fvalue_to_string_repr calls to expect an allocated buffer (and not a passed in one). Now changing signature to force an allocated buffer. Added wmem in case that can be taken advantage of within epan (and since the function signature was changing anyway). Change-Id: Ica1ac4a9a182ce0e73303856329e198d9d525b7b Reviewed-on: https://code.wireshark.org/review/15343 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan')
-rw-r--r--epan/dfilter/dfilter-macro.c4
-rw-r--r--epan/dfilter/dfvm.c6
-rw-r--r--epan/ftypes/ftypes.c19
-rw-r--r--epan/ftypes/ftypes.h12
-rw-r--r--epan/print.c10
-rw-r--r--epan/proto.c22
-rw-r--r--epan/wslua/wslua_field.c18
7 files changed, 47 insertions, 44 deletions
diff --git a/epan/dfilter/dfilter-macro.c b/epan/dfilter/dfilter-macro.c
index a971633dbb..74c90e0f04 100644
--- a/epan/dfilter/dfilter-macro.c
+++ b/epan/dfilter/dfilter-macro.c
@@ -55,7 +55,7 @@ void dump_dfilter_macro_t(const dfilter_macro_t *m, const char *function, const
static gboolean free_value(gpointer k _U_, gpointer v, gpointer u _U_) {
fvt_cache_entry_t* e = (fvt_cache_entry_t*)v;
- g_free(e->repr);
+ wmem_free(NULL, e->repr);
g_free(e);
return TRUE;
}
@@ -78,7 +78,7 @@ static gboolean fvt_cache_cb(proto_node * node, gpointer data _U_) {
}
e = g_new(fvt_cache_entry_t,1);
e->name = finfo->hfinfo->abbrev,
- e->repr = fvalue_to_string_repr(&(finfo->value), FTREPR_DFILTER, finfo->hfinfo->display, NULL);
+ e->repr = fvalue_to_string_repr(NULL, &(finfo->value), FTREPR_DFILTER, finfo->hfinfo->display);
e->usable = TRUE;
g_hash_table_insert(fvt_cache,(void*)finfo->hfinfo->abbrev,e);
}
diff --git a/epan/dfilter/dfvm.c b/epan/dfilter/dfvm.c
index dd7d7bac38..c942f89bcd 100644
--- a/epan/dfilter/dfvm.c
+++ b/epan/dfilter/dfvm.c
@@ -109,13 +109,13 @@ dfvm_dump(FILE *f, dfilter_t *df)
switch (insn->op) {
case PUT_FVALUE:
- value_str = fvalue_to_string_repr(arg1->value.fvalue,
- FTREPR_DFILTER, BASE_NONE, NULL);
+ value_str = fvalue_to_string_repr(NULL, arg1->value.fvalue,
+ FTREPR_DFILTER, BASE_NONE);
fprintf(f, "%05d PUT_FVALUE\t%s <%s> -> reg#%u\n",
id, value_str,
fvalue_type_name(arg1->value.fvalue),
arg2->value.numeric);
- g_free(value_str);
+ wmem_free(NULL, value_str);
break;
case CHECK_EXISTS:
case READ_TREE:
diff --git a/epan/ftypes/ftypes.c b/epan/ftypes/ftypes.c
index 5425dbcdbe..6f57620ad1 100644
--- a/epan/ftypes/ftypes.c
+++ b/epan/ftypes/ftypes.c
@@ -376,21 +376,22 @@ fvalue_string_repr_len(fvalue_t *fv, ftrepr_t rtype, int field_display)
}
char *
-fvalue_to_string_repr(fvalue_t *fv, ftrepr_t rtype, int field_display, char *buf)
+fvalue_to_string_repr(wmem_allocator_t *scope, fvalue_t *fv, ftrepr_t rtype, int field_display)
{
+ char *buf;
+ int len;
if (fv->ftype->val_to_string_repr == NULL) {
/* no value-to-string-representation function, so the value cannot be represented */
return NULL;
}
- if (!buf) {
- int len;
- if ((len = fvalue_string_repr_len(fv, rtype, field_display)) >= 0) {
- buf = (char *)g_malloc0(len + 1);
- } else {
- /* the value cannot be represented in the given representation type (rtype) */
- return NULL;
- }
+
+ if ((len = fvalue_string_repr_len(fv, rtype, field_display)) >= 0) {
+ buf = (char *)wmem_alloc0(scope, len + 1);
+ } else {
+ /* the value cannot be represented in the given representation type (rtype) */
+ return NULL;
}
+
fv->ftype->val_to_string_repr(fv, rtype, field_display, buf);
return buf;
}
diff --git a/epan/ftypes/ftypes.h b/epan/ftypes/ftypes.h
index 0a29022f6f..9eb86ac0f2 100644
--- a/epan/ftypes/ftypes.h
+++ b/epan/ftypes/ftypes.h
@@ -25,6 +25,7 @@
#define __FTYPES_H__
#include <glib.h>
+#include "../wmem/wmem.h"
#include "ws_symbol_export.h"
#ifdef __cplusplus
@@ -256,20 +257,15 @@ int
fvalue_string_repr_len(fvalue_t *fv, ftrepr_t rtype, int field_display);
/* Creates the string representation of the field value.
- * If given non-NULL 'buf', the string is written at the memory
- * location pointed to by 'buf'. If 'buf' is NULL, new memory
- * is malloc'ed and the string representation is written there.
- * The pointer to the beginning of the string representation is
- * returned. If 'buf' was NULL, this points to the newly-allocated
- * memory. if 'buf' was non-NULL, then the return value will be
- * 'buf'.
+ * Memory for the buffer is allocated based on wmem allocator
+ * provided.
*
* field_display parameter should be a BASE_ value (enum field_display_e)
* BASE_NONE should be used if field information isn't available.
*
* Returns NULL if the string cannot be represented in the given rtype.*/
WS_DLL_PUBLIC char *
-fvalue_to_string_repr(fvalue_t *fv, ftrepr_t rtype, int field_display, char *buf);
+fvalue_to_string_repr(wmem_allocator_t *scope, fvalue_t *fv, ftrepr_t rtype, int field_display);
WS_DLL_PUBLIC ftenum_t
fvalue_type_ftenum(fvalue_t *fv);
diff --git a/epan/print.c b/epan/print.c
index 566af2ee2b..6f8a7592e0 100644
--- a/epan/print.c
+++ b/epan/print.c
@@ -404,13 +404,13 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
fputs("\" show=\"\" value=\"", pdata->fh);
break;
default:
- dfilter_string = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, fi->hfinfo->display, NULL);
+ dfilter_string = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, fi->hfinfo->display);
if (dfilter_string != NULL) {
fputs("\" show=\"", pdata->fh);
print_escaped_xml(pdata->fh, dfilter_string);
}
- g_free(dfilter_string);
+ wmem_free(NULL, dfilter_string);
/*
* XXX - should we omit "value" for any fields?
@@ -1439,9 +1439,11 @@ gchar* get_node_field_value(field_info* fi, epan_dissect_t* edt)
* FT_NONE can be checked when using -T fields */
return g_strdup("1");
default:
- dfilter_string = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, fi->hfinfo->display, NULL);
+ dfilter_string = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, fi->hfinfo->display);
if (dfilter_string != NULL) {
- return dfilter_string;
+ gchar* ret = g_strdup(dfilter_string);
+ wmem_free(NULL, dfilter_string);
+ return ret;
} else {
return get_field_hex_value(edt->pi.data_src, fi);
}
diff --git a/epan/proto.c b/epan/proto.c
index 09bd4857e6..203a4d303b 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -5232,21 +5232,21 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
break;
case FT_IEEE_11073_SFLOAT:
- str = fvalue_to_string_repr(&finfo->value, FTREPR_DISPLAY, hfinfo->display, NULL);
+ str = fvalue_to_string_repr(NULL, &finfo->value, FTREPR_DISPLAY, hfinfo->display);
g_snprintf(result+offset_r, size-offset_r,
"%s: %s",
hfinfo->name, str);
- g_free(str);
+ wmem_free(NULL, str);
offset_r = (int)strlen(result);
break;
case FT_IEEE_11073_FLOAT:
- str = fvalue_to_string_repr(&finfo->value, FTREPR_DISPLAY, hfinfo->display, NULL);
+ str = fvalue_to_string_repr(NULL, &finfo->value, FTREPR_DISPLAY, hfinfo->display);
g_snprintf(result+offset_r, size-offset_r,
"%s: %s",
hfinfo->name, str);
offset_r = (int)strlen(result);
- g_free(str);
+ wmem_free(NULL, str);
break;
case FT_IPXNET: /*XXX really No column custom ?*/
@@ -7322,18 +7322,18 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
break;
case FT_IEEE_11073_SFLOAT:
- tmp = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, hfinfo->display, NULL);
+ tmp = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, hfinfo->display);
g_snprintf(label_str, ITEM_LABEL_LENGTH,
"%s: %s",
hfinfo->name, tmp);
- g_free(tmp);
+ wmem_free(NULL, tmp);
break;
case FT_IEEE_11073_FLOAT:
- tmp = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, hfinfo->display, NULL);
+ tmp = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, hfinfo->display);
g_snprintf(label_str, ITEM_LABEL_LENGTH,
"%s: %s",
hfinfo->name, tmp);
- g_free(tmp);
+ wmem_free(NULL, tmp);
break;
default:
@@ -8832,16 +8832,16 @@ construct_match_selected_string(field_info *finfo, epan_dissect_t *edt,
* 1 byte for trailing NUL.
*/
if (filter != NULL) {
- char* str;
+ char* str;
dfilter_len = fvalue_string_repr_len(&finfo->value,
FTREPR_DFILTER, finfo->hfinfo->display);
dfilter_len += abbrev_len + 4 + 1;
*filter = (char *)wmem_alloc0(NULL, dfilter_len);
/* Create the string */
- str = fvalue_to_string_repr(&finfo->value, FTREPR_DFILTER, finfo->hfinfo->display, NULL);
+ str = fvalue_to_string_repr(NULL, &finfo->value, FTREPR_DFILTER, finfo->hfinfo->display);
g_snprintf(*filter, dfilter_len, "%s == %s", hfinfo->abbrev, str);
- g_free(str);
+ wmem_free(NULL, str);
}
break;
}
diff --git a/epan/wslua/wslua_field.c b/epan/wslua/wslua_field.c
index 0dc79760a3..48a5a6c6a3 100644
--- a/epan/wslua/wslua_field.c
+++ b/epan/wslua/wslua_field.c
@@ -161,12 +161,16 @@ WSLUA_METAMETHOD FieldInfo__call(lua_State* L) {
}
case FT_STRING:
case FT_STRINGZ: {
- gchar* repr = fvalue_to_string_repr(&fi->ws_fi->value,FTREPR_DISPLAY,BASE_NONE,NULL);
+ gchar* repr = fvalue_to_string_repr(NULL, &fi->ws_fi->value,FTREPR_DISPLAY,BASE_NONE);
if (repr)
- lua_pushstring(L,repr);
+ {
+ lua_pushstring(L, repr);
+ wmem_free(NULL, repr);
+ }
else
+ {
luaL_error(L,"field cannot be represented as string because it may contain invalid characters");
-
+ }
return 1;
}
case FT_NONE:
@@ -215,16 +219,16 @@ WSLUA_METAMETHOD FieldInfo__tostring(lua_State* L) {
gchar* repr = NULL;
if (fi->ws_fi->hfinfo->type == FT_PROTOCOL || fi->ws_fi->hfinfo->type == FT_PCRE) {
- repr = fvalue_to_string_repr(&fi->ws_fi->value,FTREPR_DFILTER,BASE_NONE,NULL);
+ repr = fvalue_to_string_repr(NULL, &fi->ws_fi->value,FTREPR_DFILTER,BASE_NONE);
}
else {
- repr = fvalue_to_string_repr(&fi->ws_fi->value,FTREPR_DISPLAY,fi->ws_fi->hfinfo->display,NULL);
+ repr = fvalue_to_string_repr(NULL, &fi->ws_fi->value,FTREPR_DISPLAY,fi->ws_fi->hfinfo->display);
}
if (repr) {
lua_pushstring(L,repr);
- /* fvalue_to_string_repr() g_malloc's the string's buffer */
- g_free(repr);
+ /* fvalue_to_string_repr() wmem_alloc's the string's buffer */
+ wmem_free(NULL, repr);
}
else {
lua_pushstring(L,"(unknown)");