diff options
| author | Franklin Wei <git@fwei.tk> | 2017-01-04 21:12:17 -0500 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2017-01-04 21:12:17 -0500 |
| commit | dbee727664a69b82ce582e252501ec47e5533596 (patch) | |
| tree | 06d7ee5b182d213b3bc00cae17e2af22be64626a /apps | |
| parent | 1464cb942b0308c356c667896299d6cf6675bea6 (diff) | |
| download | rockbox-dbee727664a69b82ce582e252501ec47e5533596.zip rockbox-dbee727664a69b82ce582e252501ec47e5533596.tar.gz rockbox-dbee727664a69b82ce582e252501ec47e5533596.tar.bz2 rockbox-dbee727664a69b82ce582e252501ec47e5533596.tar.xz | |
puzzles: fix a minor bug in the configuration screen
- when an invalid string setting was entered, the string value would
continue to be used after being freed
Change-Id: I3a9da016f6f32eac8636b9f55e4e09006bc6059e
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/plugins/puzzles/rockbox.c | 20 |
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; } |