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 <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2012-09-22 19:07:50 +03:00
parent c4c636fb4f
commit 921bc51c87

View file

@ -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 {