perf tests: Fix memory leak by expr__find_other() in test__expr() [Linux 4.19.36]

perf tests: Fix memory leak by expr__find_other() in test__expr() [Linux 4.19.36]

This Linux kernel change "perf tests: Fix memory leak by expr__find_other() in test__expr()" is included in the Linux 4.19.36 release. This change is authored by Changbin Du <changbin.du [at]> on Sat Mar 16 16:05:55 2019 +0800. The commit for this change in Linux stable tree is 2c843ae (patch) which is from upstream commit f97a899. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream f97a899.

perf tests: Fix memory leak by expr__find_other() in test__expr()

[ Upstream commit f97a8991d3b998e518f56794d879f645964de649 ]

  ==7506==ERROR: LeakSanitizer: detected memory leaks

  Direct leak of 13 byte(s) in 3 object(s) allocated from:
      #0 0x7f03339d6070 in __interceptor_strdup (/usr/lib/x86_64-linux-gnu/
      #1 0x5625e53aaef0 in expr__find_other util/expr.y:221
      #2 0x5625e51bcd3f in test__expr tests/expr.c:52
      #3 0x5625e51528e6 in run_test tests/builtin-test.c:358
      #4 0x5625e5152baf in test_and_print tests/builtin-test.c:388
      #5 0x5625e51543fe in __cmd_test tests/builtin-test.c:583
      #6 0x5625e515572f in cmd_test tests/builtin-test.c:722
      #7 0x5625e51c3fb8 in run_builtin /home/changbin/work/linux/tools/perf/perf.c:302
      #8 0x5625e51c44f7 in handle_internal_command /home/changbin/work/linux/tools/perf/perf.c:354
      #9 0x5625e51c48fb in run_argv /home/changbin/work/linux/tools/perf/perf.c:398
      #10 0x5625e51c5069 in main /home/changbin/work/linux/tools/perf/perf.c:520
      #11 0x7f033214d09a in __libc_start_main (/lib/x86_64-linux-gnu/

Signed-off-by: Changbin Du <>
Cc: Alexei Starovoitov <>
Cc: Andi Kleen <>
Cc: Daniel Borkmann <>
Cc: Jiri Olsa <>
Cc: Namhyung Kim <>
Cc: Peter Zijlstra <>
Cc: Steven Rostedt (VMware) <>
Fixes: 075167363f8b ("perf tools: Add a simple expression parser for JSON")
Signed-off-by: Arnaldo Carvalho de Melo <>
Signed-off-by: Sasha Levin <>

There are 5 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 tools/perf/tests/expr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c
index 01f0706..9acc1e8 100644
--- a/tools/perf/tests/expr.c
+++ b/tools/perf/tests/expr.c
@@ -19,7 +19,7 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)
    const char *p;
    const char **other;
    double val;
-   int ret;
+   int i, ret;
    struct parse_ctx ctx;
    int num_other;

@@ -56,6 +56,9 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)
    TEST_ASSERT_VAL("find other", !strcmp(other[1], "BAZ"));
    TEST_ASSERT_VAL("find other", !strcmp(other[2], "BOZO"));
    TEST_ASSERT_VAL("find other", other[3] == NULL);
+   for (i = 0; i < num_other; i++)
+       free((void *)other[i]);
    free((void *)other);

    return 0;

Leave a Reply

Your email address will not be published. Required fields are marked *