changeset 4892:dc6de8ad81ae

[gaim-migrate @ 5222] memleak fixes in all kinds of places. mainly in smiley themes. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Tue, 25 Mar 2003 06:37:45 +0000
parents cfa045006bec
children 8d2b454e20ea
files src/gtkconv.c src/gtkimhtml.c src/prefs.c src/themes.c src/ui.h
diffstat 5 files changed, 34 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkconv.c	Tue Mar 25 06:35:45 2003 +0000
+++ b/src/gtkconv.c	Tue Mar 25 06:37:45 2003 +0000
@@ -3776,6 +3776,7 @@
 		gtk_widget_destroy(gtkconv->dialogs.log);
 
 	gtk_widget_destroy(gtkconv->tab_cont);
+	g_object_unref(gtkconv->tab_cont);
 
 	if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
 		if (gtkconv->u.im->icon_timer != 0)
--- a/src/gtkimhtml.c	Tue Mar 25 06:35:45 2003 +0000
+++ b/src/gtkimhtml.c	Tue Mar 25 06:37:45 2003 +0000
@@ -149,19 +149,10 @@
 };
 static guint signals [LAST_SIGNAL] = { 0 };
 
-static gboolean
-gtk_smiley_tree_destroy_from_hash(gpointer key, gpointer value,
-		gpointer user_data)
-{
-	gtk_smiley_tree_destroy(value);
-	return TRUE;
-}
-
 static void
 gtk_imhtml_finalize (GObject *object)
 {
 	GtkIMHtml *imhtml = GTK_IMHTML(object);
-	g_hash_table_foreach_remove(imhtml->smiley_data, gtk_smiley_tree_destroy_from_hash, NULL);
 	g_hash_table_destroy(imhtml->smiley_data);
 	gtk_smiley_tree_destroy(imhtml->default_smilies);
 	gdk_cursor_unref(imhtml->hand_cursor);
@@ -225,7 +216,8 @@
 	imhtml->show_smileys = TRUE;
 	imhtml->show_comments = TRUE;
 
-	imhtml->smiley_data = g_hash_table_new (g_str_hash, g_str_equal);
+	imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal,
+			g_free, gtk_smiley_tree_destroy);
 	imhtml->default_smilies = gtk_smiley_tree_new();
 
 	g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL);
@@ -462,7 +454,7 @@
 	else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) {
 	} else {
 		tree = gtk_smiley_tree_new();
-		g_hash_table_insert(imhtml->smiley_data, sml, tree);
+		g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree);
 	}
 
 	gtk_smiley_tree_insert (tree, smiley);
@@ -1187,11 +1179,12 @@
 	return str;
 }
 
-void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) 
-{ 
+void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml)
+{
 	g_hash_table_destroy(imhtml->smiley_data);
 	gtk_smiley_tree_destroy(imhtml->default_smilies);
-	imhtml->smiley_data = g_hash_table_new (g_str_hash, g_str_equal);
+	imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal,
+			g_free, gtk_smiley_tree_destroy);
 	imhtml->default_smilies = gtk_smiley_tree_new();
 }
 void       gtk_imhtml_show_smileys     (GtkIMHtml        *imhtml,
--- a/src/prefs.c	Tue Mar 25 06:35:45 2003 +0000
+++ b/src/prefs.c	Tue Mar 25 06:37:45 2003 +0000
@@ -242,6 +242,7 @@
 				   1, description,
 				   2, theme->path,
 				   -1);
+		g_object_unref(G_OBJECT(pixbuf));
 		g_free(description);
 		themes = themes->next;
 		if (current_smiley_theme && !strcmp(theme->path, current_smiley_theme->path)) {
@@ -740,11 +741,6 @@
 		      "SOCKS 5", PROXY_SOCKS5,
 		      "HTTP", PROXY_HTTP, NULL);
 
-	table = gtk_table_new(2, 2, FALSE);
-	gtk_container_set_border_width(GTK_CONTAINER(table), 5);
-	gtk_table_set_col_spacings(GTK_TABLE(table), 5);
-	gtk_table_set_row_spacings(GTK_TABLE(table), 5);
-
 	vbox = make_frame(ret, _("Proxy Server"));
 	prefs_proxy_frame = vbox;
 
@@ -1782,8 +1778,10 @@
 	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_v), FALSE);
 	gtk_widget_show(tree_v);
 	/* icons */
+	/* XXX: to be used at a later date
 	cell = gtk_cell_renderer_pixbuf_new ();
 	column = gtk_tree_view_column_new_with_attributes ("icons", cell, "pixbuf", 0, NULL);
+	*/
 
 	/* text */
 	cell = gtk_cell_renderer_text_new ();
--- a/src/themes.c	Tue Mar 25 06:35:45 2003 +0000
+++ b/src/themes.c	Tue Mar 25 06:37:45 2003 +0000
@@ -38,7 +38,7 @@
 	struct smiley_list *next;
 };
 
-GSList *smiley_themes;
+GSList *smiley_themes = NULL;
 struct smiley_theme *current_smiley_theme;
 
 void smiley_themeize(GtkWidget *imhtml)
@@ -60,7 +60,7 @@
 	}
 }
 
-struct smiley_theme *load_smiley_theme(const char *file, gboolean load)
+void load_smiley_theme(const char *file, gboolean load)
 {
 	FILE *f = fopen(file, "r");
 	char buf[256];
@@ -69,32 +69,31 @@
 	struct smiley_list *list = NULL;
 	GSList *lst = smiley_themes;
 	char *dirname;
-	gboolean old=FALSE;
+
+	if (!f)
+		return;
 
 	while (lst) {
 		struct smiley_theme *thm = lst->data;
 		if (!strcmp(thm->path, file)) {
 			theme = thm;
-			old = TRUE;
 			break;
 		}
 		lst = lst->next;
 	}
 
-	if (!f)
-		return NULL;
 	if (!theme) {
 		theme = g_new0(struct smiley_theme, 1);
 		theme->path = g_strdup(file);
+		smiley_themes = g_slist_append(smiley_themes, theme);
 	}
 
 	dirname = g_path_get_dirname(file);
 	if (load) {
 		if (current_smiley_theme) {
 			GSList *already_freed = NULL;
-			struct smiley_list *wer = current_smiley_theme->list;
+			struct smiley_list *wer = current_smiley_theme->list, *wer2;
 			while (wer) {
-				GSList *already_freed = NULL;
 				while (wer->smileys) {
 					GtkIMHtmlSmiley *uio = wer->smileys->data;
 					if (uio->icon)
@@ -107,7 +106,10 @@
 					g_free(uio);
 					wer->smileys=g_slist_remove(wer->smileys, uio);
 				}
-				wer = wer->next;
+				wer2 = wer->next;
+				g_free(wer->sml);
+				g_free(wer);
+				wer = wer2;
 			}
 			current_smiley_theme->list = NULL;
 			g_slist_free(already_freed);
@@ -137,15 +139,23 @@
 				theme->list = child;
 			list = child;
 		} else if (!g_ascii_strncasecmp(i, "Name=", strlen("Name="))) {
+			if(theme->name)
+				g_free(theme->name);
 			theme->name = g_strdup(i+ strlen("Name="));
 			theme->name[strlen(theme->name)-1] = 0;
 		} else if (!g_ascii_strncasecmp(i, "Description=", strlen("Description="))) {
+			if(theme->desc)
+				g_free(theme->desc);
 			theme->desc = g_strdup(i + strlen("Description="));
 			theme->desc[strlen(theme->desc)-1] = 0;
 		} else if (!g_ascii_strncasecmp(i, "Icon=", strlen("Icon="))) {
+			if(theme->icon)
+				g_free(theme->icon);
 			theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL);
 			theme->icon[strlen(theme->icon)-1] = 0;
 		} else if (!g_ascii_strncasecmp(i, "Author=", strlen("Author="))) {
+			if(theme->author)
+				g_free(theme->author);
 			theme->author = g_strdup(i + strlen("Author="));
 			theme->author[strlen(theme->author)-1] = 0;
 		} else if (load && list) {
@@ -191,7 +201,6 @@
 	}
 
 	g_free(dirname);
-	return old ? NULL : theme;
 }
 
 void smiley_theme_probe()
@@ -199,7 +208,6 @@
 	GDir *dir;
 	const gchar *file;
 	gchar *path;
-	struct smiley_theme *smile;
 	int l;
 
 	char* probedirs[3];
@@ -211,20 +219,18 @@
 		if (dir) {
 			while ((file = g_dir_read_name(dir))) {
 				path = g_build_filename(probedirs[l], file, "theme", NULL);
-				
+
 				/* Here we check to see that the theme has proper syntax.
 				 * We set the second argument to FALSE so that it doesn't load
 				 * the theme yet.
 				 */
-				if ((smile = load_smiley_theme(path, FALSE))) {
-					smiley_themes = g_slist_append(smiley_themes, smile);
-				}
+				load_smiley_theme(path, FALSE);
 				g_free(path);
 			}
 			g_dir_close(dir);
 		} else if (l == 1) {
 			mkdir(probedirs[l], S_IRUSR | S_IWUSR | S_IXUSR);
-		}	
+		}
 		g_free(probedirs[l]);
 	}
 }
--- a/src/ui.h	Tue Mar 25 06:35:45 2003 +0000
+++ b/src/ui.h	Tue Mar 25 06:37:45 2003 +0000
@@ -332,7 +332,7 @@
 /* Functions in themes.c */
 extern void smiley_themeize(GtkWidget *);
 extern void smiley_theme_probe();
-extern struct smiley_theme *load_smiley_theme(const char *file, gboolean load);
+extern void load_smiley_theme(const char *file, gboolean load);
 extern GSList *get_proto_smileys(int protocol);
 
 /* Fucnctions in util.c */