[PATCH] Fixed some small memory leaks

Dirk Hohndel dirk at hohndel.org
Mon Oct 1 14:12:06 PDT 2012


Thanks, Lubomir.

Pushed.

/D

"Lubomir I. Ivanov" <neolit123 at gmail.com> writes:

> From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
>
> Looks like a GtkEntryCompletion object created with
> gtk_entry_completion_new() should be unreferenced after usage
> (e.g. post gtk_entry_set_completion())
>
> In info.c:get_combo_box_entry_text(), moved the free(..) line outside,
> so that we can free regardless.
>
> Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
> ---
>  equipment.c | 1 +
>  gtk-gui.c   | 1 +
>  info.c      | 5 +++--
>  3 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/equipment.c b/equipment.c
> index 503f238..e30f40d 100644
> --- a/equipment.c
> +++ b/equipment.c
> @@ -941,6 +941,7 @@ static void cylinder_widget(GtkWidget *vbox, struct cylinder_widget *cylinder, G
>  	gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model));
>  	g_signal_connect(completion, "match-selected", G_CALLBACK(completion_cb), cylinder);
>  	gtk_entry_set_completion(entry, completion);
> +	g_object_unref(completion);
>  
>  	hbox = gtk_hbox_new(FALSE, 3);
>  	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
> diff --git a/gtk-gui.c b/gtk-gui.c
> index 8e21f31..0a4ee48 100644
> --- a/gtk-gui.c
> +++ b/gtk-gui.c
> @@ -705,6 +705,7 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
>  		/* Flush the changes out to the system */
>  		subsurface_flush_conf();
>  	}
> +	free((void *)current_default);
>  	gtk_widget_destroy(dialog);
>  }
>  
> diff --git a/info.c b/info.c
> index 5b90633..3dfaa33 100644
> --- a/info.c
> +++ b/info.c
> @@ -264,6 +264,7 @@ static GtkComboBoxEntry *text_entry(GtkWidget *box, const char *label, GtkListSt
>  	gtk_entry_completion_set_inline_selection(completion, TRUE);
>  	gtk_entry_completion_set_popup_single_match(completion, FALSE);
>  	gtk_entry_set_completion(entry, completion);
> +	g_object_unref(completion);
>  
>  	return GTK_COMBO_BOX_ENTRY(combo_box);
>  }
> @@ -427,9 +428,9 @@ static void save_dive_info_changes(struct dive *dive, struct dive *master, struc
>  	new_text = get_combo_box_entry_text(info->rating, &rating_string, star_strings[master->rating]);
>  	if (new_text) {
>  		dive->rating = get_rating(rating_string);
> -		free(rating_string);
> -		changed =1;
> +		changed = 1;
>  	}
> +	free(rating_string);
>  
>  	if (info->notes) {
>  		old_text = dive->notes;
> -- 
> 1.7.11.msysgit.0
>
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

-- 
Dirk Hohndel
Intel Open Source Technology Center


More information about the subsurface mailing list