diff options
author | Peter Wu <peter@lekensteyn.nl> | 2019-01-25 22:55:24 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2019-01-27 09:43:05 +0000 |
commit | 03e13a6a9fbba7cad7dbc00a1fe1b6eb44b1c16c (patch) | |
tree | 96fbf28e5e87d56ea2c281c66ec9fdd3c7a4821d /epan/wslua/wslua_proto.c | |
parent | 311d087bbdec5e6a93d740327fdff82ad6a13dde (diff) |
wslua: fix memleaks related to Proto and Pref
Proto objects were only freed while reloading Lua plugins, be sure to
release these on program exit too. Fix missing deallocation of heur_list
(matches per-protocol cleanup in proto_cleanup_base).
Be sure to keep a reference to the "Pref" object after registering it to
a Proto, otherwise it could be garbage-collected early, resulting in
memleaks (because the preference was still in use).
Fixes a lot of memory leaks reported by ASAN for tests, ten tests were
affected by Proto_new leaks, four were affected by the new_pref leaks.
Change-Id: Ica52718849a33eda614775f533dc0fcefec9cc74
Reviewed-on: https://code.wireshark.org/review/31746
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'epan/wslua/wslua_proto.c')
-rw-r--r-- | epan/wslua/wslua_proto.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c index 3583b6d459..d57afebc9b 100644 --- a/epan/wslua/wslua_proto.c +++ b/epan/wslua/wslua_proto.c @@ -618,9 +618,11 @@ int wslua_deregister_protocols(lua_State* L) { if (proto->prefs_module) { Pref pref; prefs_deregister_protocol(proto->hfid); + /* Preferences are unregistered, now free its memory via Pref__gc */ for (pref = proto->prefs.next; pref; pref = pref->next) { - g_free(pref->name); - pref->name = NULL; /* Deregister Pref, freed in Pref__gc */ + int pref_ref = pref->ref; + pref->ref = LUA_NOREF; + luaL_unref(L, LUA_REGISTRYINDEX, pref_ref); } } if (proto->expert_module) { |