From 921bc51c879648afc81bfb1b1f1a154e8b97ce6e Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Sat, 22 Sep 2012 19:07:50 +0300 Subject: Make sure memory for default_dive_computer_device is allocated When calling gtk-gui.c:set_default_dive_computer_device(), first free memory at default_dive_computer_device and then use strdup(). This fixed a case, where after selecting a device for the first time in the "Download" dialog, then pressing "OK" followed by "Cancel" (after a device error) the device text is garbled the next time the dialog is opened. Signed-off-by: Lubomir I. Ivanov --- gtk-gui.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gtk-gui.c b/gtk-gui.c index cb46da43b..b93f0d590 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -70,7 +70,9 @@ static void set_default_dive_computer_device(const char *name) return; if (is_default_dive_computer_device(name)) return; - default_dive_computer_device = name; + if (default_dive_computer_device) + free((void *)default_dive_computer_device); + default_dive_computer_device = strdup(name); subsurface_set_conf("dive_computer_device", PREF_STRING, name); } @@ -1105,6 +1107,8 @@ void exit_ui(void) free((char *)default_filename); if (existing_filename) free((void *)existing_filename); + if (default_dive_computer_device) + free((void *)default_dive_computer_device); } typedef struct { -- cgit v1.2.3-70-g09d2