SF.net SVN: geany:[4230] trunk/plugins/filebrowser.c

ntrel at users.sourceforge.net ntrel at xxxxx
Tue Sep 22 17:53:17 UTC 2009


Revision: 4230
          http://geany.svn.sourceforge.net/geany/?rev=4230&view=rev
Author:   ntrel
Date:     2009-09-22 17:53:07 +0000 (Tue, 22 Sep 2009)

Log Message:
-----------
Make foreach_slist_free() macro to free each node whilst iterating.

Modified Paths:
--------------
    trunk/plugins/filebrowser.c

Modified: trunk/plugins/filebrowser.c
===================================================================
--- trunk/plugins/filebrowser.c	2009-09-22 17:46:33 UTC (rev 4229)
+++ trunk/plugins/filebrowser.c	2009-09-22 17:53:07 UTC (rev 4230)
@@ -228,11 +228,15 @@
 }
 
 
+/* Reuses list to free each node, so list must be a variable */
+#define foreach_slist_free(node, list) \
+	for (node = list, list = NULL; g_slist_free_1(list), node != NULL; list = node, node = node->next)
+
 /* recreate the tree model from current_dir. */
 static void refresh(void)
 {
 	gchar *utf8_dir;
-	GSList *list;
+	GSList *list, *node;
 
 	/* don't clear when the new path doesn't exist */
 	if (! g_file_test(current_dir, G_FILE_TEST_EXISTS))
@@ -249,19 +253,13 @@
 	list = utils_get_file_list(current_dir, NULL, NULL);
 	if (list != NULL)
 	{
-		GSList *node;
-
 		/* free filenames & nodes as we go through the list */
-		for (node = list; node != NULL;)
+		foreach_slist_free(node, list)
 		{
 			gchar *fname = node->data;
-			GSList *old;
 
 			add_item(fname);
 			g_free(fname);
-			old = node;
-			node = node->next;
-			g_slist_free_1(old);
 		}
 	}
 	gtk_entry_completion_set_model(entry_completion, GTK_TREE_MODEL(file_store));


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list