• Masahiro Yamada's avatar
    kconfig: fix memory leak from range properties · ae1eff03
    Masahiro Yamada authored
    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: default avatarMasahiro Yamada <masahiroy@kernel.org>
    ae1eff03
symbol.c 28.1 KB