Ethereal-dev: [Ethereal-dev] Mem fix for filtering (match_selected_cb_do)

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Jirka Novak <j.novak@xxxxxxxxxxxx>
Date: Thu, 17 Jan 2002 14:40:41 +0100
Hi,

this patch add correct freing of temp string in compositing of filter expression.

							Jirka Novak

P.S. Thanks for /* XXX */ note in source
Index: ethereal/gtk/main.c
===================================================================
RCS file: /cvsroot/ethereal/gtk/main.c,v
retrieving revision 1.229
diff -u -r1.229 main.c
--- main.c	2002/01/13 20:35:11	1.229
+++ main.c	2002/01/17 13:34:27
@@ -233,24 +233,24 @@
     filter_te = gtk_object_get_data(GTK_OBJECT(data), E_DFILTER_TE_KEY);
     g_assert(filter_te);
 
-    ptr = gtk_entry_get_text(GTK_ENTRY(filter_te));
+    ptr = gtk_editable_get_chars(GTK_EDITABLE(filter_te),0,-1);
 
     switch (action&MATCH_SELECTED_MASK) {
 
     case MATCH_SELECTED_REPLACE:
-	ptr = text;
+	ptr = g_strdup(text);
 	break;
 
     case MATCH_SELECTED_AND:
 	if ((!ptr) || (0 == strlen(ptr)))
-	    ptr = text;
+	    ptr = g_strdup(text);
 	else
 	    ptr = g_strconcat("(", ptr, ") && (", text, ")", NULL);
 	break;
 
     case MATCH_SELECTED_OR:
 	if ((!ptr) || (0 == strlen(ptr)))
-	    ptr = text;
+	    ptr = g_strdup(text);
 	else
 	    ptr = g_strconcat("(", ptr, ") || (", text, ")", NULL);
 	break;
@@ -284,9 +284,9 @@
     if (action&MATCH_SELECTED_APPLY_NOW)
 	filter_packets(&cfile, ptr);
 
-    /* Don't g_free(text) here. filter_packets() will do it the next time
+    /* Don't g_free(ptr) here. filter_packets() will do it the next time
        it's called. */
-    /* XXX - what about ptr? */
+    g_free(text);
 }
 
 void