]> git.itanic.dy.fi Git - linux-stable/commit
kconfig: fix memory leak from range properties
authorMasahiro Yamada <masahiroy@kernel.org>
Wed, 15 Nov 2023 04:16:53 +0000 (13:16 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Fri, 17 Nov 2023 04:24:08 +0000 (13:24 +0900)
commitae1eff0349f2e908fc083630e8441ea6dc434dc0
treeeaecd0aa59fa4c44633232c88b59f408804653cb
parent76020731d4ee897411ce4a73916ed805ea15d946
kconfig: fix memory leak from range properties

Currently, sym_validate_range() duplicates the range string using
xstrdup(), which is overwritten by a subsequent sym_calc_value() call.
It results in a memory leak.

Instead, only the pointer should be copied.

Below is a test case, with a summary from Valgrind.

[Test Kconfig]

  config FOO
          int "foo"
          range 10 20

[Test .config]

  CONFIG_FOO=0

[Before]

  LEAK SUMMARY:
     definitely lost: 3 bytes in 1 blocks
     indirectly lost: 0 bytes in 0 blocks
       possibly lost: 0 bytes in 0 blocks
     still reachable: 17,465 bytes in 21 blocks
          suppressed: 0 bytes in 0 blocks

[After]

  LEAK SUMMARY:
     definitely lost: 0 bytes in 0 blocks
     indirectly lost: 0 bytes in 0 blocks
       possibly lost: 0 bytes in 0 blocks
     still reachable: 17,462 bytes in 20 blocks
          suppressed: 0 bytes in 0 blocks

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
scripts/kconfig/symbol.c