Fix memory leaks with gtk_container_get_children().

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4305 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2009-10-12 16:31:38 +00:00
parent 717f0b6009
commit 2ed2fe1af6
4 changed files with 27 additions and 22 deletions

View File

@ -16,11 +16,13 @@
src/project.c, src/search.c, src/editor.c, src/ui_utils.c, src/project.c, src/search.c, src/editor.c, src/ui_utils.c,
plugins/classbuilder.c: plugins/classbuilder.c:
Make utils_free_pointers() take 4 arguments, add to API. Make utils_free_pointers() take 4 arguments, add to API.
* src/templates.c, src/tools.c, src/ui_utils.c:
Fix memory leaks with gtk_container_get_children().
2009-10-12 Lex Trotman <elextr(at)gmail(dot)com> 2009-10-12 Lex Trotman <elextr(at)gmail(dot)com>
* build.c: * src/build.c:
Ensure that old style build config is not loaded if it does not exist. Ensure that old style build config is not loaded if it does not exist.

View File

@ -687,6 +687,8 @@ void templates_free_templates(void)
{ {
gtk_widget_destroy(GTK_WIDGET(item->data)); gtk_widget_destroy(GTK_WIDGET(item->data));
} }
g_list_free(children);
/* Shouldn't unrefing destroy children anyway? */ /* Shouldn't unrefing destroy children anyway? */
g_object_unref(new_with_template_menu); g_object_unref(new_with_template_menu);
new_with_template_menu = NULL; new_with_template_menu = NULL;

View File

@ -343,22 +343,20 @@ static void cc_show_dialog_custom_commands(void)
{ {
/* get all hboxes which contain a label and an entry element */ /* get all hboxes which contain a label and an entry element */
GList *children = gtk_container_get_children(GTK_CONTAINER(cc.box)); GList *children = gtk_container_get_children(GTK_CONTAINER(cc.box));
GList *tmp; GList *node, *list;
GSList *result_list = NULL; GSList *result_list = NULL;
gint j = 0; gint j = 0;
gint len = 0; gint len = 0;
gchar **result = NULL; gchar **result = NULL;
const gchar *text; const gchar *text;
while (children != NULL) foreach_list(node, children)
{ {
/* get the contents of each hbox */ /* get the contents of each hbox */
tmp = gtk_container_get_children(GTK_CONTAINER(children->data)); list = gtk_container_get_children(GTK_CONTAINER(node->data));
/* first element of the list is the label, so skip it and get the entry element */ /* first element of the list is the label, so skip it and get the entry element */
tmp = tmp->next; text = gtk_entry_get_text(GTK_ENTRY(list->next->data));
text = gtk_entry_get_text(GTK_ENTRY(tmp->data));
/* if the content of the entry is non-empty, add it to the result array */ /* if the content of the entry is non-empty, add it to the result array */
if (text[0] != '\0') if (text[0] != '\0')
@ -366,7 +364,7 @@ static void cc_show_dialog_custom_commands(void)
result_list = g_slist_append(result_list, g_strdup(text)); result_list = g_slist_append(result_list, g_strdup(text));
len++; len++;
} }
children = children->next; g_list_free(list);
} }
/* create a new null-terminated array but only if there any commands defined */ /* create a new null-terminated array but only if there any commands defined */
if (len > 0) if (len > 0)
@ -400,7 +398,7 @@ static void cc_on_custom_command_menu_activate(GtkMenuItem *menuitem, gpointer u
GeanyDocument *doc = document_get_current(); GeanyDocument *doc = document_get_current();
gint i, len; gint i, len;
gboolean enable; gboolean enable;
GList *children; GList *children, *node;
g_return_if_fail(doc != NULL); g_return_if_fail(doc != NULL);
@ -409,15 +407,15 @@ static void cc_on_custom_command_menu_activate(GtkMenuItem *menuitem, gpointer u
children = gtk_container_get_children(GTK_CONTAINER(user_data)); children = gtk_container_get_children(GTK_CONTAINER(user_data));
len = g_list_length(children); len = g_list_length(children);
i = 0; i = 0;
while (children != NULL) foreach_list(node, children)
{ {
if (i == (len - 2)) if (i == (len - 2))
break; /* stop before the last two elements (the seperator and the set entry) */ break; /* stop before the last two elements (the seperator and the set entry) */
gtk_widget_set_sensitive(GTK_WIDGET(children->data), enable); gtk_widget_set_sensitive(GTK_WIDGET(node->data), enable);
children = children->next;
i++; i++;
} }
g_list_free(children);
} }
@ -484,22 +482,19 @@ void tools_create_insert_custom_command_menu_items(void)
GtkMenu *menu_edit = GTK_MENU(ui_lookup_widget(main_widgets.window, "send_selection_to2_menu")); GtkMenu *menu_edit = GTK_MENU(ui_lookup_widget(main_widgets.window, "send_selection_to2_menu"));
GtkMenu *menu_popup = GTK_MENU(ui_lookup_widget(main_widgets.editor_menu, "send_selection_to1_menu")); GtkMenu *menu_popup = GTK_MENU(ui_lookup_widget(main_widgets.editor_menu, "send_selection_to1_menu"));
GtkWidget *item; GtkWidget *item;
GList *me_children; GList *me_children, *node;
GList *mp_children; GList *mp_children;
static gboolean signal_set = FALSE; static gboolean signal_set = FALSE;
/* first clean the menus to be able to rebuild them */ /* first clean the menus to be able to rebuild them */
me_children = gtk_container_get_children(GTK_CONTAINER(menu_edit)); me_children = gtk_container_get_children(GTK_CONTAINER(menu_edit));
mp_children = gtk_container_get_children(GTK_CONTAINER(menu_popup)); mp_children = gtk_container_get_children(GTK_CONTAINER(menu_popup));
while (me_children != NULL) foreach_list(node, me_children)
{ gtk_widget_destroy(GTK_WIDGET(node->data));
gtk_widget_destroy(GTK_WIDGET(me_children->data)); foreach_list(node, mp_children)
gtk_widget_destroy(GTK_WIDGET(mp_children->data)); gtk_widget_destroy(GTK_WIDGET(node->data));
g_list_free(me_children);
me_children = me_children->next; g_list_free(mp_children);
mp_children = mp_children->next;
}
if (ui_prefs.custom_commands == NULL || g_strv_length(ui_prefs.custom_commands) == 0) if (ui_prefs.custom_commands == NULL || g_strv_length(ui_prefs.custom_commands) == 0)
{ {

View File

@ -1109,6 +1109,7 @@ static void recent_file_loaded(const gchar *utf8_filename, GeanyRecentFiles *grf
item = g_list_find_custom(children, utf8_filename, (GCompareFunc) find_recent_file_item); item = g_list_find_custom(children, utf8_filename, (GCompareFunc) find_recent_file_item);
if (item != NULL) if (item != NULL)
gtk_widget_destroy(GTK_WIDGET(item->data)); gtk_widget_destroy(GTK_WIDGET(item->data));
g_list_free(children);
if (grf->toolbar != NULL) if (grf->toolbar != NULL)
{ {
@ -1116,6 +1117,7 @@ static void recent_file_loaded(const gchar *utf8_filename, GeanyRecentFiles *grf
item = g_list_find_custom(children, utf8_filename, (GCompareFunc) find_recent_file_item); item = g_list_find_custom(children, utf8_filename, (GCompareFunc) find_recent_file_item);
if (item != NULL) if (item != NULL)
gtk_widget_destroy(GTK_WIDGET(item->data)); gtk_widget_destroy(GTK_WIDGET(item->data));
g_list_free(children);
} }
/* now prepend a new menuitem for the filename, /* now prepend a new menuitem for the filename,
* first for the recent files menu in the menu bar */ * first for the recent files menu in the menu bar */
@ -1158,6 +1160,8 @@ static void update_recent_menu(GeanyRecentFiles *grf)
item = g_list_next(item); item = g_list_next(item);
} }
} }
g_list_free(children);
/* create item for the menu bar menu */ /* create item for the menu bar menu */
tmp = gtk_menu_item_new_with_label(filename); tmp = gtk_menu_item_new_with_label(filename);
gtk_widget_show(tmp); gtk_widget_show(tmp);
@ -1178,6 +1182,8 @@ static void update_recent_menu(GeanyRecentFiles *grf)
item = g_list_next(item); item = g_list_next(item);
} }
} }
g_list_free(children);
/* create item for the tool bar menu */ /* create item for the tool bar menu */
tmp = gtk_menu_item_new_with_label(filename); tmp = gtk_menu_item_new_with_label(filename);
gtk_widget_show(tmp); gtk_widget_show(tmp);