]> git.baikalelectronics.ru Git - kernel.git/commit
perf/core: Fix a memory leak in perf_event_parse_addr_filter()
authorkiyin(尹亮) <kiyin@tencent.com>
Wed, 4 Nov 2020 05:23:22 +0000 (08:23 +0300)
committerIngo Molnar <mingo@kernel.org>
Sat, 7 Nov 2020 12:07:26 +0000 (13:07 +0100)
commit4effce8fe3a522c16838ddf766ed2ae478e34bd1
treed3e577e32989820c2559ab0a212d971b2e049139
parent636a419a10a3f4f1d5b396b398523d5025b55282
perf/core: Fix a memory leak in perf_event_parse_addr_filter()

As shown through runtime testing, the "filename" allocation is not
always freed in perf_event_parse_addr_filter().

There are three possible ways that this could happen:

 - It could be allocated twice on subsequent iterations through the loop,
 - or leaked on the success path,
 - or on the failure path.

Clean up the code flow to make it obvious that 'filename' is always
freed in the reallocation path and in the two return paths as well.

We rely on the fact that kfree(NULL) is NOP and filename is initialized
with NULL.

This fixes the leak. No other side effects expected.

[ Dan Carpenter: cleaned up the code flow & added a changelog. ]
[ Ingo Molnar: updated the changelog some more. ]

Fixes: aeab82993f45 ("perf/core: Introduce address range filtering")
Signed-off-by: "kiyin(尹亮)" <kiyin@tencent.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: "Srivatsa S. Bhat" <srivatsa@csail.mit.edu>
Cc: Anthony Liguori <aliguori@amazon.com>
--
 kernel/events/core.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
kernel/events/core.c