summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2017-01-04 21:12:17 -0500
committerFranklin Wei <git@fwei.tk>2017-01-04 21:12:17 -0500
commitdbee727664a69b82ce582e252501ec47e5533596 (patch)
tree06d7ee5b182d213b3bc00cae17e2af22be64626a
parent1464cb942b0308c356c667896299d6cf6675bea6 (diff)
downloadrockbox-dbee727664a69b82ce582e252501ec47e5533596.tar.gz
rockbox-dbee727664a69b82ce582e252501ec47e5533596.zip
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
-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 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
685static void do_configure_item(config_item *cfg) 685/* return value is only meaningful when type == C_STRING */
686static 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
729const char *config_formatter(int sel, void *data, char *buf, size_t len) 731const 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 }