diff options
author | Michael Mann <mmann78@netscape.net> | 2016-05-10 16:04:14 -0400 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2016-05-10 22:49:08 +0000 |
commit | 1dccd1ee072722fbe6d5e1a9d726a7e87d191f76 (patch) | |
tree | 4d4059e0eead7303c6d7420a3828332d26bd79fa /epan/wslua | |
parent | 931603c4b84a5e69e94e3bfd3c84332e664062ab (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>
Diffstat (limited to 'epan/wslua')
-rw-r--r-- | epan/wslua/wslua_field.c | 18 |
1 files changed, 11 insertions, 7 deletions
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)"); |