pidgin: cb808713: Fix various leaks of the basename/filena..

darkrain42 at pidgin.im darkrain42 at pidgin.im
Tue Sep 1 23:21:21 EDT 2009


-----------------------------------------------------------------
Revision: cb80871347fc6f79b6b8b31e853a9f84433ed1a9
Ancestor: b4a95ea62b81a06ffc1993912471c511b786efdd
Author: darkrain42 at pidgin.im
Date: 2009-09-02T03:17:25
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/cb80871347fc6f79b6b8b31e853a9f84433ed1a9

Modified files:
        pidgin/gtkutils.c

ChangeLog: 

Fix various leaks of the basename/filename/entire list in pidgin_dnd_file_manage.

These were pointed out by WebcamWonder.

-------------- next part --------------
============================================================
--- pidgin/gtkutils.c	439850f3e9de4db4a560eb82525b7229b687961c
+++ pidgin/gtkutils.c	03954ae90744b694e40bdf8e4aa91a187bdafd44
@@ -1533,7 +1533,6 @@ pidgin_dnd_file_manage(GtkSelectionData 
 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,14 +1541,19 @@ pidgin_dnd_file_manage(GtkSelectionData 
 #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 @@ pidgin_dnd_file_manage(GtkSelectionData 
 
 			g_free(str);
 			g_free(str2);
-
 			continue;
 		}
 
@@ -1629,6 +1632,12 @@ pidgin_dnd_file_manage(GtkSelectionData 
 						    (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 @@ pidgin_dnd_file_manage(GtkSelectionData 
 				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)


More information about the Commits mailing list