Fixed some memory leaks related to string configuration entries

Each time we retrieve a string configuration entry via
subsurface_get_conf(), all the multiplatform methods in linux.c,
macos.c, windows.c allocate memory for the returned value.

In gtk-gui.c, lets try to release the memory at:
default_dive_computer_vendor, default_dive_computer_product, divelist_font
before assigning a new address to these pointers.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2012-10-04 23:52:09 +03:00 committed by Dirk Hohndel
parent f928be5061
commit b272fb8c3b

View file

@ -60,6 +60,10 @@ static void set_default_dive_computer(const char *vendor, const char *product)
return; return;
if (is_default_dive_computer(vendor, product)) if (is_default_dive_computer(vendor, product))
return; return;
if (default_dive_computer_vendor)
free((void *)default_dive_computer_vendor);
if (default_dive_computer_product)
free((void *)default_dive_computer_product);
default_dive_computer_vendor = vendor; default_dive_computer_vendor = vendor;
default_dive_computer_product = product; default_dive_computer_product = product;
subsurface_set_conf("dive_computer_vendor", PREF_STRING, vendor); subsurface_set_conf("dive_computer_vendor", PREF_STRING, vendor);
@ -673,6 +677,8 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
/* Make sure to flush any modified old dive data with old units */ /* Make sure to flush any modified old dive data with old units */
update_dive(NULL); update_dive(NULL);
if (divelist_font)
free((void *)divelist_font);
divelist_font = strdup(gtk_font_button_get_font_name(GTK_FONT_BUTTON(font))); divelist_font = strdup(gtk_font_button_get_font_name(GTK_FONT_BUTTON(font)));
set_divelist_font(divelist_font); set_divelist_font(divelist_font);