From a3e5044d4fbc636c1ac5be12586de338f55c4ddd Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Sun, 16 Oct 2011 21:03:06 +0200 Subject: [PATCH] Plug a few memory leaks These leaks actually were not "real" leaks since the memory will anyway be kept until quit. Fixing those only makes the code "cleaner" and will prevent them to "hide" some other (real) ones at debug times. --- src/ui_utils.c | 11 ++++++++--- src/vte.c | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ui_utils.c b/src/ui_utils.c index 0c7248ec..5866a711 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -1883,6 +1883,12 @@ static void on_config_file_clicked(GtkWidget *widget, gpointer user_data) } +static void free_on_closure_notify(gpointer data, GClosure *closure) +{ + g_free(data); +} + + /* @note You should connect to the "document-save" signal yourself to detect * if the user has just saved the config file, reloading it. */ void ui_add_config_file_menu_item(const gchar *real_path, const gchar *label, GtkContainer *parent) @@ -1905,9 +1911,8 @@ void ui_add_config_file_menu_item(const gchar *real_path, const gchar *label, Gt gtk_widget_show(item); gtk_container_add(parent, item); - g_signal_connect(item, "activate", G_CALLBACK(on_config_file_clicked), - /* this memory is kept */ - g_strdup(real_path)); + g_signal_connect_data(item, "activate", G_CALLBACK(on_config_file_clicked), + g_strdup(real_path), free_on_closure_notify, 0); } diff --git a/src/vte.c b/src/vte.c index ce9572c7..9bf7c624 100644 --- a/src/vte.c +++ b/src/vte.c @@ -248,6 +248,7 @@ static void create_vte(void) /* create menu now so copy/paste shortcuts work */ vc->menu = vte_create_popup_menu(); + g_object_ref_sink(vc->menu); frame = gtk_frame_new(NULL); @@ -291,6 +292,7 @@ void vte_close(void) * this prevents a segfault on X close window if the message window is hidden */ gtk_widget_destroy(vc->vte); gtk_widget_destroy(vc->menu); + g_object_unref(vc->menu); g_free(vc->emulation); g_free(vc->shell); g_free(vc->font);