summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/puzzles/rockbox.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/apps/plugins/puzzles/rockbox.c b/apps/plugins/puzzles/rockbox.c
index f1c3d45..86dc9cf 100644
--- a/apps/plugins/puzzles/rockbox.c
+++ b/apps/plugins/puzzles/rockbox.c
@@ -682,7 +682,8 @@ static int list_choose(const char *list_str, const char *title)
}
}
-static void do_configure_item(config_item *cfg)
+/* return value is only meaningful when type == C_STRING */
+static bool do_configure_item(config_item *cfg)
{
switch(cfg->type)
{
@@ -696,11 +697,11 @@ static void do_configure_item(config_item *cfg)
if(rb->kbd_input(newstr, MAX_STRLEN) < 0)
{
sfree(newstr);
- break;
+ return false;
}
sfree(cfg->sval);
cfg->sval = newstr;
- break;
+ return true;
}
case C_BOOLEAN:
{
@@ -724,6 +725,7 @@ static void do_configure_item(config_item *cfg)
fatal("bad type");
break;
}
+ return false;
}
const char *config_formatter(int sel, void *data, char *buf, size_t len)
@@ -779,12 +781,22 @@ static void config_menu(void)
config_item old;
int pos = rb->gui_synclist_get_sel_pos(&list);
memcpy(&old, config + pos, sizeof(old));
- do_configure_item(config + pos);
+ char *old_str;
+ if(old.type == C_STRING)
+ old_str = dupstr(old.sval);
+ bool freed_str = do_configure_item(config + pos);
char *err = midend_set_config(me, CFG_SETTINGS, config);
if(err)
{
rb->splash(HZ, err);
memcpy(config + pos, &old, sizeof(old));
+ if(freed_str)
+ config[pos].sval = old_str;
+ }
+ else if(old.type == C_STRING)
+ {
+ /* success, and we duplicated the old string, so free it */
+ sfree(old_str);
}
break;
}