diff options
Diffstat (limited to 'apps/plugins/puzzles')
-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 f1c3d45e76..86dc9cffd4 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) | |||
682 | } | 682 | } |
683 | } | 683 | } |
684 | 684 | ||
685 | static void do_configure_item(config_item *cfg) | 685 | /* return value is only meaningful when type == C_STRING */ |
686 | static bool do_configure_item(config_item *cfg) | ||
686 | { | 687 | { |
687 | switch(cfg->type) | 688 | switch(cfg->type) |
688 | { | 689 | { |
@@ -696,11 +697,11 @@ static void do_configure_item(config_item *cfg) | |||
696 | if(rb->kbd_input(newstr, MAX_STRLEN) < 0) | 697 | if(rb->kbd_input(newstr, MAX_STRLEN) < 0) |
697 | { | 698 | { |
698 | sfree(newstr); | 699 | sfree(newstr); |
699 | break; | 700 | return false; |
700 | } | 701 | } |
701 | sfree(cfg->sval); | 702 | sfree(cfg->sval); |
702 | cfg->sval = newstr; | 703 | cfg->sval = newstr; |
703 | break; | 704 | return true; |
704 | } | 705 | } |
705 | case C_BOOLEAN: | 706 | case C_BOOLEAN: |
706 | { | 707 | { |
@@ -724,6 +725,7 @@ static void do_configure_item(config_item *cfg) | |||
724 | fatal("bad type"); | 725 | fatal("bad type"); |
725 | break; | 726 | break; |
726 | } | 727 | } |
728 | return false; | ||
727 | } | 729 | } |
728 | 730 | ||
729 | const char *config_formatter(int sel, void *data, char *buf, size_t len) | 731 | const char *config_formatter(int sel, void *data, char *buf, size_t len) |
@@ -779,12 +781,22 @@ static void config_menu(void) | |||
779 | config_item old; | 781 | config_item old; |
780 | int pos = rb->gui_synclist_get_sel_pos(&list); | 782 | int pos = rb->gui_synclist_get_sel_pos(&list); |
781 | memcpy(&old, config + pos, sizeof(old)); | 783 | memcpy(&old, config + pos, sizeof(old)); |
782 | do_configure_item(config + pos); | 784 | char *old_str; |
785 | if(old.type == C_STRING) | ||
786 | old_str = dupstr(old.sval); | ||
787 | bool freed_str = do_configure_item(config + pos); | ||
783 | char *err = midend_set_config(me, CFG_SETTINGS, config); | 788 | char *err = midend_set_config(me, CFG_SETTINGS, config); |
784 | if(err) | 789 | if(err) |
785 | { | 790 | { |
786 | rb->splash(HZ, err); | 791 | rb->splash(HZ, err); |
787 | memcpy(config + pos, &old, sizeof(old)); | 792 | memcpy(config + pos, &old, sizeof(old)); |
793 | if(freed_str) | ||
794 | config[pos].sval = old_str; | ||
795 | } | ||
796 | else if(old.type == C_STRING) | ||
797 | { | ||
798 | /* success, and we duplicated the old string, so free it */ | ||
799 | sfree(old_str); | ||
788 | } | 800 | } |
789 | break; | 801 | break; |
790 | } | 802 | } |