aboutsummaryrefslogtreecommitdiffstats
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
parent931603c4b84a5e69e94e3bfd3c84332e664062ab (diff)
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>
-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
-rw-r--r--plugins/mate/mate_util.c4
-rw-r--r--rawshark.c9
-rw-r--r--ui/cli/tap-diameter-avp.c4
-rw-r--r--ui/gtk/packet_panes.c4
-rw-r--r--ui/qt/proto_tree.cpp4
12 files changed, 59 insertions, 57 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)");
diff --git a/plugins/mate/mate_util.c b/plugins/mate/mate_util.c
index 169eaae727..828e1ac118 100644
--- a/plugins/mate/mate_util.c
+++ b/plugins/mate/mate_util.c
@@ -313,11 +313,11 @@ extern AVP* new_avp_from_finfo(const gchar* name, field_info* finfo) {
new_avp_val->n = scs_subscribe(avp_strings, name);
- repr = fvalue_to_string_repr(&finfo->value,FTREPR_DISPLAY,finfo->hfinfo->display,NULL);
+ repr = fvalue_to_string_repr(NULL, &finfo->value,FTREPR_DISPLAY,finfo->hfinfo->display);
if (repr) {
value = scs_subscribe(avp_strings, repr);
- g_free(repr);
+ wmem_free(NULL, repr);
#ifdef _AVP_DEBUGGING
dbg_print (dbg_avp,2,dbg_fp,"new_avp_from_finfo: from string: %s",value);
#endif
diff --git a/rawshark.c b/rawshark.c
index 41ca4ba716..cd59d9fdf9 100644
--- a/rawshark.c
+++ b/rawshark.c
@@ -1189,9 +1189,8 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
* e.g: ip.hdr_len
*/
fs_len = fvalue_string_repr_len(&finfo->value, FTREPR_DFILTER, finfo->hfinfo->display);
- fs_buf = fvalue_to_string_repr(&finfo->value,
- FTREPR_DFILTER, finfo->hfinfo->display,
- NULL);
+ fs_buf = fvalue_to_string_repr(NULL, &finfo->value,
+ FTREPR_DFILTER, finfo->hfinfo->display);
fs_ptr = fs_buf;
/* String types are quoted. Remove them. */
@@ -1280,14 +1279,14 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
}
}
printf(" %d=\"%s\"", cmd_line_index, label_s->str);
- g_free(fs_buf);
+ wmem_free(NULL, fs_buf);
return TRUE;
}
if(finfo->value.ftype->val_to_string_repr)
{
printf(" %d=\"%s\"", cmd_line_index, fs_ptr);
- g_free(fs_buf);
+ wmem_free(NULL, fs_buf);
return TRUE;
}
diff --git a/ui/cli/tap-diameter-avp.c b/ui/cli/tap-diameter-avp.c
index bb3602fc6e..02106cd9f4 100644
--- a/ui/cli/tap-diameter-avp.c
+++ b/ui/cli/tap-diameter-avp.c
@@ -106,11 +106,11 @@ diam_tree_to_csv(proto_node *node, gpointer data)
ftype = fvalue_type_ftenum(&fi->value);
if (ftype != FT_NONE && ftype != FT_PROTOCOL) {
/* convert value to string */
- val_tmp = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, hfi->display, NULL);
+ val_tmp = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, hfi->display);
if (val_tmp)
{
val_str = g_strdup(val_tmp);
- g_free(val_tmp);
+ wmem_free(NULL, val_tmp);
} else
val_str = g_strdup_printf("unsupported type: %s", ftype_name(ftype));
diff --git a/ui/gtk/packet_panes.c b/ui/gtk/packet_panes.c
index 128c71555a..6ee8fea51a 100644
--- a/ui/gtk/packet_panes.c
+++ b/ui/gtk/packet_panes.c
@@ -1334,10 +1334,10 @@ tree_view_follow_link(field_info *fi)
cf_goto_frame(&cfile, fi->value.value.uinteger);
}
if(FI_GET_FLAG(fi, FI_URL) && IS_FT_STRING(fi->hfinfo->type)) {
- url = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, fi->hfinfo->display, NULL);
+ url = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, fi->hfinfo->display);
if(url){
browser_open_url(url);
- g_free(url);
+ wmem_free(NULL, url);
}
}
}
diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp
index f2bca27db0..f8aa48bbab 100644
--- a/ui/qt/proto_tree.cpp
+++ b/ui/qt/proto_tree.cpp
@@ -582,11 +582,11 @@ void ProtoTree::itemDoubleClick(QTreeWidgetItem *item, int) {
if(FI_GET_FLAG(fi, FI_URL) && IS_FT_STRING(fi->hfinfo->type)) {
gchar *url;
- url = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, fi->hfinfo->display, NULL);
+ url = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, fi->hfinfo->display);
if(url){
// browser_open_url(url);
QDesktopServices::openUrl(QUrl(url));
- g_free(url);
+ wmem_free(NULL, url);
}
}
}