fix the memory leak problem mentioned lately by adding and using color_filters_cleanup()
authorulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 3 Oct 2006 23:24:48 +0000 (23:24 +0000)
committerulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 3 Oct 2006 23:24:48 +0000 (23:24 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@19422 f5534014-38df-0310-8fa8-9805f1628bb7

color_filters.c
color_filters.h
file.c

index c818351..1cf3480 100644 (file)
 
 static gboolean read_users_filters(GSList **cfl);
 
-
+/* the currently active filters */
 static GSList *color_filter_list = NULL;
 
+/* keep "old" deleted filters in this list until 
+ * the dissection no longer needs them (e.g. file is closed) */
+static GSList *color_filter_deleted_list = NULL;
+
 /* Color Filters can en-/disabled. */
 gboolean filters_enabled = TRUE;
 
@@ -146,7 +150,7 @@ color_filter_list_clone(GSList *cfl)
 void
 color_filters_init(void)
 {
-       /* delete all existing filters */
+       /* delete all currently existing filters */
        color_filter_list_delete(&color_filter_list);
 
        /* try to read the users filters */
@@ -155,6 +159,13 @@ color_filters_init(void)
                color_filters_read_globals(&color_filter_list);
 }
 
+void
+color_filters_cleanup(void)
+{
+        /* delete the previously deleted filters */
+        color_filter_list_delete(&color_filter_deleted_list);
+}
+
 static void
 color_filters_clone_cb(gpointer filter_arg, gpointer user_data)
 {
@@ -189,17 +200,9 @@ color_filter_compile_cb(gpointer filter_arg, gpointer *cfl)
 void
 color_filters_apply(GSList *cfl)
 {
-        /* remove "old" entries */
-/*        color_filter_list_delete(&color_filter_list);*/
-
-        /* deleting the color filters crashes unpredictably 
-         * (e.g. sometimes while clearing the list) :-(
-         *
-         * for now, just clear the list and let the filters remain in memory
-         * until WS is closed -> memory leak
-         *
-         * XXX - move the filters to a "removed list" as before
-         * and delete them if the file is closed (or on rescan of packets or such?) */
+        /* "move" old entries to the deleted list
+         * we must keep them until the dissection no longer needs them */
+        color_filter_deleted_list = g_slist_concat(color_filter_deleted_list, color_filter_list);
         color_filter_list = NULL;
 
         /* clone all list entries from edit to normal list */
index b9b7d78..beceea5 100644 (file)
@@ -48,7 +48,8 @@ typedef struct _color_filter {
 /** Init the color filters (incl. initial read from file). */
 void color_filters_init(void);
 
-
+/** Cleanup remaining color filter zombies */
+void color_filters_cleanup(void);
 
 /** Color filters currently used?
  *
diff --git a/file.c b/file.c
index 4bf10cc..6252203 100644 (file)
--- a/file.c
+++ b/file.c
@@ -347,6 +347,8 @@ cf_close(capture_file *cf)
   /* close things, if not already closed before */
   if(cf->state != FILE_CLOSED) {
 
+         color_filters_cleanup();
+
          cf_reset_state(cf);
 
          cleanup_dissection();