perf lock: Fix a memory leak on an error path
authorIan Rogers <irogers@google.com>
Mon, 9 Oct 2023 18:39:15 +0000 (11:39 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 12 Oct 2023 17:01:57 +0000 (10:01 -0700)
If a memory allocation fails then the strdup-ed string needs
freeing. Detected by clang-tidy.

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: llvm@lists.linux.dev
Cc: Ming Wang <wangming01@loongson.cn>
Cc: Tom Rix <trix@redhat.com>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20231009183920.200859-15-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/builtin-lock.c

index fa7419978353976ba0db07f0736c43c9ec0a9ecc..a3ff2f4edbaa5064b040b256eaee1361a34122e5 100644 (file)
@@ -2478,6 +2478,7 @@ static int parse_call_stack(const struct option *opt __maybe_unused, const char
                entry = malloc(sizeof(*entry) + strlen(tok) + 1);
                if (entry == NULL) {
                        pr_err("Memory allocation failure\n");
+                       free(s);
                        return -1;
                }