aboutsummaryrefslogtreecommitdiffstats
path: root/epan/packet.c
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-06-24 01:54:19 +0200
committerMichael Mann <mmann78@netscape.net>2015-07-03 23:10:22 +0000
commitd52837d10dd63827acb6f42af7f32ca82fb1fe21 (patch)
tree0a16917ecfa97274673da41fb2ade214fbf784d0 /epan/packet.c
parentfdb85029fd9b22b221f7123905f1bad66c04ce91 (diff)
packet: add cleanup routines support
Currently reassembly tables are not freed on shutdown. This makes memleak debugging more difficult due to noise. Support cleanup routines that can do smarter things. After this change, "init" routines are not called anymore when closing files. Further changes should split init routines to cleanup routines as needed. Change-Id: Ib0b2cef6dd9c16905259063ac2c2fdfb7e066be6 Reviewed-on: https://code.wireshark.org/review/9135 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/packet.c')
-rw-r--r--epan/packet.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/epan/packet.c b/epan/packet.c
index 07ae74f76b..bbf8fd1c6c 100644
--- a/epan/packet.c
+++ b/epan/packet.c
@@ -193,11 +193,11 @@ set_actual_length(tvbuff_t *tvb, const guint specified_len)
}
}
-/* Allow protocols to register "init" routines, which are called before
- we make a pass through a capture file and dissect all its packets
- (e.g., when we read in a new capture file, or run a "filter packets"
- or "colorize packets" pass over the current capture file). */
+/* 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;
+static GSList *cleanup_routines;
void
register_init_routine(void (*func)(void))
@@ -205,24 +205,22 @@ register_init_routine(void (*func)(void))
init_routines = g_slist_prepend(init_routines, (gpointer)func);
}
+void
+register_cleanup_routine(void (*func)(void))
+{
+ cleanup_routines = g_slist_prepend(cleanup_routines, (gpointer)func);
+}
+
typedef void (*void_func_t)(void);
/* Initialize all data structures used for dissection. */
static void
-call_init_routine(gpointer routine, gpointer dummy _U_)
+call_routine(gpointer routine, gpointer dummy _U_)
{
void_func_t func = (void_func_t)routine;
(*func)();
}
-/*
- * XXX - for now, these are the same; the "init" routines free whatever
- * stuff is left over from any previous dissection, and then initialize
- * their tables.
- *
- * We should probably split that into "init" and "cleanup" routines, for
- * cleanliness' sake.
- */
void
init_dissection(void)
{
@@ -241,7 +239,7 @@ init_dissection(void)
epan_circuit_init();
/* Initialize protocol-specific variables. */
- g_slist_foreach(init_routines, &call_init_routine, NULL);
+ g_slist_foreach(init_routines, &call_routine, NULL);
/* Initialize the stream-handling tables */
stream_init();
@@ -261,9 +259,8 @@ cleanup_dissection(void)
/* Cleanup the table of circuits. */
epan_circuit_cleanup();
- /* TODO: Introduce cleanup_routines */
/* Cleanup protocol-specific variables. */
- g_slist_foreach(init_routines, &call_init_routine, NULL);
+ g_slist_foreach(cleanup_routines, &call_routine, NULL);
/* Cleanup the stream-handling tables */
stream_cleanup();