Lua can free tvbuffs too early

Lua-created tvbuffs should be kept around for the duration of pinfo's
lifetime, instead of only for the duration of frame dissection. So
instead of using the frame dissector's frame_end_routine, we'll register
a callback to wmem for pinfo pool's allocator.

Bug: 10888
Change-Id: I3e9db671c3f2a7cab9e258aca17f3be8acaf2417
Reviewed-on: https://code.wireshark.org/review/6768
Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Evan Huus <eapache@gmail.com>
Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Hadriel Kaplan <hadrielk@yahoo.com>
This commit is contained in:
Hadriel Kaplan 2015-01-24 15:58:30 -05:00
parent 716f9a3197
commit aec1bcf9a1
3 changed files with 10 additions and 5 deletions

View File

@ -131,7 +131,7 @@ WARNING: You probably don't actually need these; use them only when you're
Sometimes (though hopefully rarely) it may be necessary to store data in a wmem
pool that requires additional cleanup before it is freed. For example, perhaps
you have a pointer to a file-handle that needs to be closed. In this case, you
can register a callback with the wmem_register_cleanup_callback function
can register a callback with the wmem_register_callback function
declared in wmem_user_cb.h. Every time the memory in a pool is freed, all
registered cleanup functions are called first.

View File

@ -50,7 +50,7 @@ typedef enum _wmem_cb_event_t {
* allocator The allocator that triggered this callback.
* event The event type that triggered this callback.
* user_data Whatever user_data was originally passed to the call to
* wmem_register_cleanup_callback().
* wmem_register_callback().
* @return FALSE to unregister the callback, TRUE otherwise.
*/
typedef gboolean (*wmem_user_cb_t) (wmem_allocator_t*, wmem_cb_event_t, void*);

View File

@ -130,7 +130,9 @@ static expert_field ei_lua_proto_comments_error = EI_INIT;
dissector_handle_t lua_data_handle;
static void lua_frame_end(void)
static gboolean
lua_pinfo_end(wmem_allocator_t *allocator _U_, wmem_cb_event_t event _U_,
void *user_data _U_)
{
clear_outstanding_Tvb();
clear_outstanding_TvbRange();
@ -140,6 +142,9 @@ static void lua_frame_end(void)
clear_outstanding_PrivateTable();
clear_outstanding_TreeItem();
clear_outstanding_FieldInfo();
/* keep invoking this callback later? */
return FALSE;
}
static int wslua_not_register_menu(lua_State* LS) {
@ -201,7 +206,7 @@ int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data
"Lua Error: did not find the %s dissector in the dissectors table", pinfo->current_proto);
}
register_frame_end_routine(pinfo, lua_frame_end);
wmem_register_callback(pinfo->pool, lua_pinfo_end, NULL);
lua_pinfo = NULL;
lua_tree = NULL;
@ -301,7 +306,7 @@ gboolean heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, v
lua_pop(L, 1);
}
register_frame_end_routine(pinfo, lua_frame_end);
wmem_register_callback(pinfo->pool, lua_pinfo_end, NULL);
lua_pinfo = NULL;
lua_tree = NULL;