summaryrefslogtreecommitdiff
path: root/tools/perf/tests
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2019-07-04 18:06:20 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-07-09 16:13:27 +0300
commitd8f9da240495b50766239410f9b0c715ca506a67 (patch)
treea9fb3abcc48a72cd34a9299f081aab497325711f /tools/perf/tests
parent7f7c536f23e6afaa5d5d4b0e0958b0be8922491f (diff)
downloadlinux-d8f9da240495b50766239410f9b0c715ca506a67.tar.xz
perf tools: Use zfree() where applicable
In places where the equivalent was already being done, i.e.: free(a); a = NULL; And in placs where struct members are being freed so that if we have some erroneous reference to its struct, then accesses to freed members will result in segfaults, which we can detect faster than use after free to areas that may still have something seemingly valid. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Link: https://lkml.kernel.org/n/tip-jatyoofo5boc1bsvoig6bb6i@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests')
-rw-r--r--tools/perf/tests/dwarf-unwind.c5
-rw-r--r--tools/perf/tests/expr.c3
-rw-r--r--tools/perf/tests/mem2node.c3
-rw-r--r--tools/perf/tests/thread-map.c3
4 files changed, 9 insertions, 5 deletions
diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c
index 077c306c1cae..f33709a79335 100644
--- a/tools/perf/tests/dwarf-unwind.c
+++ b/tools/perf/tests/dwarf-unwind.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/compiler.h>
#include <linux/types.h>
+#include <linux/zalloc.h>
#include <inttypes.h>
#include <unistd.h>
#include "tests.h"
@@ -115,8 +116,8 @@ noinline int test_dwarf_unwind__thread(struct thread *thread)
}
out:
- free(sample.user_stack.data);
- free(sample.user_regs.regs);
+ zfree(&sample.user_stack.data);
+ zfree(&sample.user_regs.regs);
return err;
}
diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c
index 9acc1e80b936..ee1d88650e69 100644
--- a/tools/perf/tests/expr.c
+++ b/tools/perf/tests/expr.c
@@ -3,6 +3,7 @@
#include "util/expr.h"
#include "tests.h"
#include <stdlib.h>
+#include <linux/zalloc.h>
static int test(struct parse_ctx *ctx, const char *e, double val2)
{
@@ -58,7 +59,7 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)
TEST_ASSERT_VAL("find other", other[3] == NULL);
for (i = 0; i < num_other; i++)
- free((void *)other[i]);
+ zfree(&other[i]);
free((void *)other);
return 0;
diff --git a/tools/perf/tests/mem2node.c b/tools/perf/tests/mem2node.c
index d23ff1b68eba..520cc91af256 100644
--- a/tools/perf/tests/mem2node.c
+++ b/tools/perf/tests/mem2node.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/compiler.h>
#include <linux/bitmap.h>
+#include <linux/zalloc.h>
#include "cpumap.h"
#include "mem2node.h"
#include "tests.h"
@@ -67,7 +68,7 @@ int test__mem2node(struct test *t __maybe_unused, int subtest __maybe_unused)
T("failed: mem2node__node", -1 == mem2node__node(&map, 0x1050));
for (i = 0; i < ARRAY_SIZE(nodes); i++)
- free(nodes[i].set);
+ zfree(&nodes[i].set);
mem2node__exit(&map);
return 0;
diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c
index 4de1939b58ba..ccc17aced49e 100644
--- a/tools/perf/tests/thread-map.c
+++ b/tools/perf/tests/thread-map.c
@@ -6,6 +6,7 @@
#include "tests.h"
#include "thread_map.h"
#include "debug.h"
+#include <linux/zalloc.h>
#define NAME (const char *) "perf"
#define NAMEUL (unsigned long) NAME
@@ -133,7 +134,7 @@ int test__thread_map_remove(struct test *test __maybe_unused, int subtest __mayb
thread_map__remove(threads, 0));
for (i = 0; i < threads->nr; i++)
- free(threads->map[i].comm);
+ zfree(&threads->map[i].comm);
free(threads);
return 0;