changeset 28172:07718e5eb8ce

Fix various leaks of the basename/filename/entire list in pidgin_dnd_file_manage. These were pointed out by WebcamWonder.
author Paul Aurich <paul@darkrain42.org>
date Wed, 02 Sep 2009 03:17:25 +0000
parents 5546612e70e2
children f7bb03f0518e
files pidgin/gtkutils.c
diffstat 1 files changed, 22 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkutils.c	Tue Sep 01 23:06:25 2009 +0000
+++ b/pidgin/gtkutils.c	Wed Sep 02 03:17:25 2009 +0000
@@ -1533,7 +1533,6 @@
 void
 pidgin_dnd_file_manage(GtkSelectionData *sd, PurpleAccount *account, const char *who)
 {
-	GList *tmp;
 	GdkPixbuf *pb;
 	GList *files = purple_uri_list_extract_filenames((const gchar *)sd->data);
 	PurpleConnection *gc = purple_account_get_connection(account);
@@ -1542,13 +1541,18 @@
 #ifndef _WIN32
 	PurpleDesktopItem *item;
 #endif
+	gchar *filename = NULL;
+	gchar *basename = NULL;
 
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(who != NULL);
 
-	for(tmp = files; tmp != NULL ; tmp = g_list_next(tmp)) {
-		gchar *filename = tmp->data;
-		gchar *basename = g_path_get_basename(filename);
+	for ( ; files; files = g_list_delete_link(files, files)) {
+		g_free(filename);
+		g_free(basename);
+
+		filename = files->data;
+		basename = g_path_get_basename(filename);
 
 		/* Set the default action: don't send anything */
 		file_send_ok = FALSE;
@@ -1571,7 +1575,6 @@
 
 			g_free(str);
 			g_free(str2);
-
 			continue;
 		}
 
@@ -1629,6 +1632,12 @@
 						    (ft ? _("Send image file") : _("Insert in message")), (ft ? DND_FILE_TRANSFER : DND_IM_IMAGE),
 							NULL);
 			g_object_unref(G_OBJECT(pb));
+
+			g_free(basename);
+			while (files) {
+				g_free(files->data);
+				files = g_list_delete_link(files, files);
+			}
 			return;
 		}
 
@@ -1686,15 +1695,21 @@
 				break;
 			}
 			purple_desktop_item_unref(item);
+			g_free(basename);
+			while (files) {
+				g_free(files->data);
+				files = g_list_delete_link(files, files);
+			}
 			return;
 		}
 #endif /* _WIN32 */
 
 		/* Everything is fine, let's send */
 		serv_send_file(gc, who, filename);
-		g_free(filename);
 	}
-	g_list_free(files);
+
+	g_free(filename);
+	g_free(basename);
 }
 
 void pidgin_buddy_icon_get_scale_size(GdkPixbuf *buf, PurpleBuddyIconSpec *spec, PurpleIconScaleRules rules, int *width, int *height)