Commit 020a7e99 authored by Masahiro Yamada's avatar Masahiro Yamada Committed by Kleber Sacilotto de Souza

scripts/kallsyms: fix definitely-lost memory leak

BugLink: https://bugs.launchpad.net/bugs/1858462

[ Upstream commit 21915eca ]

build_initial_tok_table() overwrites unused sym_entry to shrink the
table size. Before the entry is overwritten, table[i].sym must be freed
since it is malloc'ed data.

This fixes the 'definitely lost' report from valgrind. I ran valgrind
against x86_64_defconfig of v5.4-rc8 kernel, and here is the summary:

[Before the fix]

  LEAK SUMMARY:
     definitely lost: 53,184 bytes in 2,874 blocks

[After the fix]

  LEAK SUMMARY:
     definitely lost: 0 bytes in 0 blocks
Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent e7525465
...@@ -455,6 +455,8 @@ static void build_initial_tok_table(void) ...@@ -455,6 +455,8 @@ static void build_initial_tok_table(void)
table[pos] = table[i]; table[pos] = table[i];
learn_symbol(table[pos].sym, table[pos].len); learn_symbol(table[pos].sym, table[pos].len);
pos++; pos++;
} else {
free(table[i].sym);
} }
} }
table_cnt = pos; table_cnt = pos;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment