kconfig: Don't leak main menus during parsing
[carl9170fw.git] / config / zconf.y
index d49ed3ae5d3e0889aa74fba98b7a5b8b6f5238c3..04c723595736f7be728eb5b4f2493071bf409efd 100644 (file)
@@ -109,7 +109,27 @@ static struct menu *current_menu, *current_entry;
 %%
 input: nl start | start;
 
-start: mainmenu_stmt stmt_list | stmt_list;
+start: mainmenu_stmt stmt_list | no_mainmenu_stmt stmt_list;
+
+/* mainmenu entry */
+
+mainmenu_stmt: T_MAINMENU prompt nl
+{
+       menu_add_prompt(P_MENU, $2, NULL);
+};
+
+/* Default main menu, if there's no mainmenu entry */
+
+no_mainmenu_stmt: /* empty */
+{
+       /*
+        * Hack: Keep the main menu title on the heap so we can safely free it
+        * later regardless of whether it comes from the 'prompt' in
+        * mainmenu_stmt or here
+        */
+       menu_add_prompt(P_MENU, strdup("Linux Kernel Configuration"), NULL);
+};
+
 
 stmt_list:
          /* empty */
@@ -352,13 +372,6 @@ if_block:
        | if_block choice_stmt
 ;
 
-/* mainmenu entry */
-
-mainmenu_stmt: T_MAINMENU prompt nl
-{
-       menu_add_prompt(P_MENU, $2, NULL);
-};
-
 /* menu entry */
 
 menu: T_MENU prompt T_EOL
@@ -507,6 +520,7 @@ word_opt: /* empty */                       { $$ = NULL; }
 
 void conf_parse(const char *name)
 {
+       const char *tmp;
        struct symbol *sym;
        int i;
 
@@ -524,8 +538,10 @@ void conf_parse(const char *name)
        if (!modules_sym)
                modules_sym = sym_find( "n" );
 
+       tmp = rootmenu.prompt->text;
        rootmenu.prompt->text = _(rootmenu.prompt->text);
        rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text);
+       free((char*)tmp);
 
        menu_finalize(&rootmenu);
        for_all_symbols(i, sym) {