epan: Properly cleanup registered postdissectors

wanted_hfids member was never properly freed. Fix indentation too.

Link: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2198
Bug: 13996
Change-Id: I8297df2158fd0ae8123223f4622ae952a218a07a
Reviewed-on: https://code.wireshark.org/review/23167
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Michael Mann 2017-08-28 12:42:59 +01:00 committed by Anders Broman
parent 1f9990b765
commit c729027731
2 changed files with 31 additions and 18 deletions

View File

@ -264,8 +264,14 @@ packet_cleanup(void)
g_hash_table_destroy(heuristic_short_names);
g_slist_foreach(shutdown_routines, &call_routine, NULL);
g_slist_free(shutdown_routines);
if (postdissectors)
if (postdissectors) {
for (guint i = 0; i < postdissectors->len; i++) {
if (POSTDISSECTORS(i).wanted_hfids) {
g_array_free(POSTDISSECTORS(i).wanted_hfids, TRUE);
}
}
g_array_free(postdissectors, TRUE);
}
}
/*
@ -3285,31 +3291,37 @@ register_postdissector(dissector_handle_t handle)
void
set_postdissector_wanted_hfids(dissector_handle_t handle, GArray *wanted_hfids)
{
guint i;
guint i;
if (!postdissectors) return;
if (!postdissectors) return;
for (i = 0; i < postdissectors->len; i++) {
if (POSTDISSECTORS(i).handle == handle) {
POSTDISSECTORS(i).wanted_hfids = wanted_hfids;
break;
}
}
for (i = 0; i < postdissectors->len; i++) {
if (POSTDISSECTORS(i).handle == handle) {
if (POSTDISSECTORS(i).wanted_hfids) {
g_array_free(POSTDISSECTORS(i).wanted_hfids, TRUE);
}
POSTDISSECTORS(i).wanted_hfids = wanted_hfids;
break;
}
}
}
void
deregister_postdissector(dissector_handle_t handle)
{
guint i;
guint i;
if (!postdissectors) return;
if (!postdissectors) return;
for (i = 0; i < postdissectors->len; i++) {
if (POSTDISSECTORS(i).handle == handle) {
postdissectors = g_array_remove_index_fast(postdissectors, i);
break;
}
}
for (i = 0; i < postdissectors->len; i++) {
if (POSTDISSECTORS(i).handle == handle) {
if (POSTDISSECTORS(i).wanted_hfids) {
g_array_free(POSTDISSECTORS(i).wanted_hfids, TRUE);
}
postdissectors = g_array_remove_index_fast(postdissectors, i);
break;
}
}
}
gboolean

View File

@ -773,7 +773,8 @@ WS_DLL_PUBLIC void register_postdissector(dissector_handle_t handle);
/*
* Specify a set of hfids that the postdissector will need.
* The GArray is an array of hfids.
* The GArray is an array of hfids (type int) and should be NULL to clear the
* list. This function will take ownership of the memory.
*/
WS_DLL_PUBLIC void set_postdissector_wanted_hfids(dissector_handle_t handle,
GArray *wanted_hfids);