kconfig: Fix choice symbol expression leak
authorUlf Magnusson <ulfalizer@gmail.com>
Sun, 8 Oct 2017 17:35:46 +0000 (19:35 +0200)
committerChristian Lamparter <chunkeey@gmail.com>
Sun, 10 Feb 2019 20:46:57 +0000 (21:46 +0100)
When propagating dependencies from parents after parsing, an expression
node is allocated if the parent symbol is a 'choice'. This node was
never freed.

Outline of leak:

if (sym && sym_is_choice(sym)) {
...
*Allocate (in this case only)*
parentdep = expr_alloc_symbol(sym);
} else if (parent->prompt)
parentdep = parent->prompt->visible.expr;
else
parentdep = parent->dep;

for (menu = parent->list; menu; menu = menu->next) {
...
*Copy*
basedep = expr_alloc_and(expr_copy(parentdep), basedep);
...
}
*parentdep lost if the parent is a choice!*

Fix by freeing 'parentdep' after the loop if the parent symbol is a
choice. Note that this only frees the expression node and not the choice
symbol itself.

Summary from Valgrind on 'menuconfig' (ARCH=x86) before the fix:

LEAK SUMMARY:
   definitely lost: 1,608 bytes in 67 blocks
   ...

Summary after the fix:

LEAK SUMMARY:
   definitely lost: 0 bytes in 0 blocks
   ...

Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
config/menu.c

index 5b2415991c3ed355ea5ad011b475d79cc6797de1..41c79bef3d075fa1122643ceb3cdae9e8289e8d5 100644 (file)
@@ -408,6 +408,9 @@ void menu_finalize(struct menu *parent)
                        }
                }
 
+               if (sym && sym_is_choice(sym))
+                       expr_free(parentdep);
+
                /*
                 * Recursively process children in the same fashion before
                 * moving on