diff options
author | Dario Lombardo <lomato@gmail.com> | 2016-12-13 12:40:22 +0100 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2017-01-19 21:40:46 +0000 |
commit | 07541f1f680c2dbbfe8a33f81102c711d768ac63 (patch) | |
tree | 7de5f44b63b8f9ef048fd5c725514c205999b8e9 /epan | |
parent | 86c4808518b4a3929f2bdc4b6bab59b87b67b6bd (diff) |
epan: add shutdown function for dissectors.
Dissectors can register shutdown functions, that will be called
just before program exit. Those function will free the memory
allocated during the init function.
Change-Id: Id88228af2cc916bfb316fe7b36d46499f6e4f8d4
Reviewed-on: https://code.wireshark.org/review/19282
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/packet.c | 34 | ||||
-rw-r--r-- | epan/packet.h | 6 |
2 files changed, 27 insertions, 13 deletions
diff --git a/epan/packet.c b/epan/packet.c index 647ec1afc9..537c9b537e 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -121,12 +121,6 @@ struct depend_dissector_list { /* Maps char *dissector_name to depend_dissector_list_t */ static GHashTable *depend_dissector_lists = NULL; -/* List of routines that are called before we make a pass through a capture file - * and dissect all its packets. See register_init_routine and - * register_cleanup_routine in packet.h */ -static GSList *init_routines = NULL; -static GSList *cleanup_routines = NULL; - /* Allow protocols to register a "cleanup" routine to be * run after the initial sequential run through the packets. * Note that the file can still be open after this; this is not @@ -221,6 +215,23 @@ packet_cache_proto_handles(void) g_assert(proto_malformed != -1); } +/* List of routines that are called before we make a pass through a capture file + * and dissect all its packets. See register_init_routine, register_cleanup_routine + * and register_shutdown_routine in packet.h */ +static GSList *init_routines = NULL; +static GSList *cleanup_routines = NULL; +static GSList *shutdown_routines = NULL; + +typedef void (*void_func_t)(void); + +/* Initialize all data structures used for dissection. */ +static void +call_routine(gpointer routine, gpointer dummy _U_) +{ + void_func_t func = (void_func_t)routine; + (*func)(); +} + void packet_cleanup(void) { @@ -232,6 +243,7 @@ packet_cleanup(void) g_hash_table_destroy(depend_dissector_lists); g_hash_table_destroy(heur_dissector_lists); g_hash_table_destroy(heuristic_short_names); + g_slist_foreach(shutdown_routines, &call_routine, NULL); } /* @@ -264,13 +276,11 @@ register_cleanup_routine(void (*func)(void)) cleanup_routines = g_slist_prepend(cleanup_routines, (gpointer)func); } -typedef void (*void_func_t)(void); - -static void -call_routine(gpointer routine, gpointer dummy _U_) +/* register a new shutdown routine */ +void +register_shutdown_routine(void (*func)(void)) { - void_func_t func = (void_func_t)routine; - (*func)(); + shutdown_routines = g_slist_prepend(shutdown_routines, (gpointer)func); } /* Initialize all data structures used for dissection. */ diff --git a/epan/packet.h b/epan/packet.h index 496501b27b..5c128d5f4c 100644 --- a/epan/packet.h +++ b/epan/packet.h @@ -647,6 +647,11 @@ WS_DLL_PUBLIC void register_init_routine(void (*func)(void)); */ WS_DLL_PUBLIC void register_cleanup_routine(void (*func)(void)); +/* + * Register a shutdown routine to call once just before program exit + */ +WS_DLL_PUBLIC void register_shutdown_routine(void (*func)(void)); + /* Initialize all data structures used for dissection. */ void init_dissection(void); @@ -685,7 +690,6 @@ WS_DLL_PUBLIC void add_new_data_source(packet_info *pinfo, tvbuff_t *tvb, /* Removes the last-added data source, if it turns out it wasn't needed */ WS_DLL_PUBLIC void remove_last_data_source(packet_info *pinfo); - /* * Return the data source name, tvb. */ |