aboutsummaryrefslogtreecommitdiffstats
path: root/epan/packet.c
diff options
context:
space:
mode:
authorDario Lombardo <lomato@gmail.com>2016-12-13 12:40:22 +0100
committerMichael Mann <mmann78@netscape.net>2017-01-19 21:40:46 +0000
commit07541f1f680c2dbbfe8a33f81102c711d768ac63 (patch)
tree7de5f44b63b8f9ef048fd5c725514c205999b8e9 /epan/packet.c
parent86c4808518b4a3929f2bdc4b6bab59b87b67b6bd (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/packet.c')
-rw-r--r--epan/packet.c34
1 files changed, 22 insertions, 12 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. */