kconfig: Don't leak 'option' arguments during parsing
authorUlf Magnusson <ulfalizer@gmail.com>
Sun, 8 Oct 2017 17:11:20 +0000 (19:11 +0200)
committerChristian Lamparter <chunkeey@gmail.com>
Sun, 10 Feb 2019 20:46:31 +0000 (21:46 +0100)
The following strings would leak before this change:

- option env="LEAKED"
- option defconfig_list="LEAKED"

These come in the form of T_WORD tokens and are always allocated on the
heap in zconf.l. Free them.

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

LEAK SUMMARY:
   definitely lost: 344,616 bytes in 14,355 blocks
   ...

Summary after the fix:

LEAK SUMMARY:
   definitely lost: 344,568 bytes in 14,352 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/zconf.y

index 7ca795404d38e2860f8c3cb046c2bbaea7c506e4..d49ed3ae5d3e0889aa74fba98b7a5b8b6f5238c3 100644 (file)
@@ -236,8 +236,10 @@ symbol_option_list:
        | symbol_option_list T_WORD symbol_option_arg
 {
        const struct kconf_id *id = kconf_id_lookup($2, strlen($2));
-       if (id && id->flags & TF_OPTION)
+       if (id && id->flags & TF_OPTION) {
                menu_add_option(id->token, $3);
+               free($3);
+       }
        else
                zconfprint("warning: ignoring unknown option %s", $2);
        free($2);