Commit d8f9da24 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7f7c536f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <stdlib.h>
#include <linux/compiler.h>
#include <linux/kernel.h>
#include <linux/zalloc.h>
#include <sys/time.h>

#include "../util/stat.h"
@@ -214,7 +215,7 @@ int bench_futex_hash(int argc, const char **argv)
				       &worker[i].futex[nfutexes-1], t);
		}

		free(worker[i].futex);
		zfree(&worker[i].futex);
	}

	print_summary();
+2 −1
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#include <subcmd/parse-options.h>
#include <linux/compiler.h>
#include <linux/kernel.h>
#include <linux/zalloc.h>
#include <errno.h>
#include "bench.h"
#include "futex.h"
@@ -217,7 +218,7 @@ int bench_futex_lock_pi(int argc, const char **argv)
			       worker[i].tid, worker[i].futex, t);

		if (multi)
			free(worker[i].futex);
			zfree(&worker[i].futex);
	}

	print_summary();
+2 −2
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@
#include "perf.h"

#include "util/build-id.h"
#include "util/util.h"
#include <subcmd/parse-options.h>
#include "util/parse-events.h"
#include "util/config.h"
@@ -54,6 +53,7 @@
#include <sys/mman.h>
#include <sys/wait.h>
#include <linux/time64.h>
#include <linux/zalloc.h>

struct switch_output {
	bool		 enabled;
@@ -1110,7 +1110,7 @@ record__switch_output(struct record *rec, bool at_exit)
		rec->switch_output.cur_file = n;
		if (rec->switch_output.filenames[n]) {
			remove(rec->switch_output.filenames[n]);
			free(rec->switch_output.filenames[n]);
			zfree(&rec->switch_output.filenames[n]);
		}
		rec->switch_output.filenames[n] = new_filename;
	} else {
+2 −2
Original line number Diff line number Diff line
@@ -1586,7 +1586,7 @@ static void runtime_stat_delete(struct perf_stat_config *config)
	for (i = 0; i < config->stats_num; i++)
		runtime_stat__exit(&config->stats[i]);

	free(config->stats);
	zfree(&config->stats);
}

static const char * const stat_report_usage[] = {
@@ -2003,7 +2003,7 @@ int cmd_stat(int argc, const char **argv)
	perf_stat__exit_aggr_mode();
	perf_evlist__free_stats(evsel_list);
out:
	free(stat_config.walltime_run);
	zfree(&stat_config.walltime_run);

	if (smi_cost && smi_reset)
		sysfs__write_int(FREEZE_ON_SMI_PATH, 0);
+3 −2
Original line number Diff line number Diff line
// 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;
}

Loading