aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2013-12-26 15:41:15 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-12-27 13:17:00 -0500
commit046625231a0397f1776eb353a4ec9ff142cd2f6b (patch)
tree6ce7ab043539d2432b135bc61f39febb3a032039 /tools
parentf5385650c02cd4373c4124c8a8fac3b5f9851e7f (diff)
perf tools: Introduce zfree
For the frequent idiom of: free(ptr); ptr = NULL; Make it expect a pointer to the pointer being freed, so that it becomes clear at first sight that the variable being freed is being modified. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-pfw02ezuab37kha18wlut7ir@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/arch/common.c3
-rw-r--r--tools/perf/builtin-annotate.c3
-rw-r--r--tools/perf/builtin-stat.c6
-rw-r--r--tools/perf/builtin-timechart.c3
-rw-r--r--tools/perf/builtin-trace.c12
-rw-r--r--tools/perf/ui/browser.c6
-rw-r--r--tools/perf/ui/browsers/hists.c6
-rw-r--r--tools/perf/ui/gtk/util.c3
-rw-r--r--tools/perf/util/alias.c6
-rw-r--r--tools/perf/util/annotate.c12
-rw-r--r--tools/perf/util/dso.c9
-rw-r--r--tools/perf/util/evlist.c9
-rw-r--r--tools/perf/util/evsel.c6
-rw-r--r--tools/perf/util/header.c3
-rw-r--r--tools/perf/util/help.c3
-rw-r--r--tools/perf/util/machine.c12
-rw-r--r--tools/perf/util/probe-event.c6
-rw-r--r--tools/perf/util/probe-finder.c24
-rw-r--r--tools/perf/util/symbol.c9
-rw-r--r--tools/perf/util/thread_map.c10
-rw-r--r--tools/perf/util/trace-event-info.c6
-rw-r--r--tools/perf/util/util.h2
22 files changed, 56 insertions, 103 deletions
diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c
index aacef07ebf31..42faf369211c 100644
--- a/tools/perf/arch/common.c
+++ b/tools/perf/arch/common.c
@@ -154,8 +154,7 @@ static int perf_session_env__lookup_binutils_path(struct perf_session_env *env,
154 } 154 }
155 if (lookup_path(buf)) 155 if (lookup_path(buf))
156 goto out; 156 goto out;
157 free(buf); 157 zfree(&buf);
158 buf = NULL;
159 } 158 }
160 159
161 if (!strcmp(arch, "arm")) 160 if (!strcmp(arch, "arm"))
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 4136f9970fd5..ab65057a0317 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -180,8 +180,7 @@ find_next:
180 * symbol, free he->ms.sym->src to signal we already 180 * symbol, free he->ms.sym->src to signal we already
181 * processed this symbol. 181 * processed this symbol.
182 */ 182 */
183 free(notes->src); 183 zfree(&notes->src);
184 notes->src = NULL;
185 } 184 }
186 } 185 }
187} 186}
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index dab98b50c9fe..106a5e5b7842 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -185,8 +185,7 @@ static int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel)
185 185
186static void perf_evsel__free_stat_priv(struct perf_evsel *evsel) 186static void perf_evsel__free_stat_priv(struct perf_evsel *evsel)
187{ 187{
188 free(evsel->priv); 188 zfree(&evsel->priv);
189 evsel->priv = NULL;
190} 189}
191 190
192static int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel) 191static int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel)
@@ -208,8 +207,7 @@ static int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel)
208 207
209static void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel) 208static void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel)
210{ 209{
211 free(evsel->prev_raw_counts); 210 zfree(&evsel->prev_raw_counts);
212 evsel->prev_raw_counts = NULL;
213} 211}
214 212
215static void perf_evlist__free_stats(struct perf_evlist *evlist) 213static void perf_evlist__free_stats(struct perf_evlist *evlist)
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 20d4212fa337..652af0b66a62 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -488,8 +488,7 @@ static const char *cat_backtrace(union perf_event *event,
488 * It seems the callchain is corrupted. 488 * It seems the callchain is corrupted.
489 * Discard all. 489 * Discard all.
490 */ 490 */
491 free(p); 491 zfree(&p);
492 p = NULL;
493 goto exit; 492 goto exit;
494 } 493 }
495 continue; 494 continue;
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index f64b5b0aa8b1..c5b4bc51175c 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -146,8 +146,7 @@ static int perf_evsel__init_tp_ptr_field(struct perf_evsel *evsel,
146 146
147static void perf_evsel__delete_priv(struct perf_evsel *evsel) 147static void perf_evsel__delete_priv(struct perf_evsel *evsel)
148{ 148{
149 free(evsel->priv); 149 zfree(&evsel->priv);
150 evsel->priv = NULL;
151 perf_evsel__delete(evsel); 150 perf_evsel__delete(evsel);
152} 151}
153 152
@@ -165,8 +164,7 @@ static int perf_evsel__init_syscall_tp(struct perf_evsel *evsel, void *handler)
165 return -ENOMEM; 164 return -ENOMEM;
166 165
167out_delete: 166out_delete:
168 free(evsel->priv); 167 zfree(&evsel->priv);
169 evsel->priv = NULL;
170 return -ENOENT; 168 return -ENOENT;
171} 169}
172 170
@@ -1278,10 +1276,8 @@ static size_t syscall_arg__scnprintf_close_fd(char *bf, size_t size,
1278 size_t printed = syscall_arg__scnprintf_fd(bf, size, arg); 1276 size_t printed = syscall_arg__scnprintf_fd(bf, size, arg);
1279 struct thread_trace *ttrace = arg->thread->priv; 1277 struct thread_trace *ttrace = arg->thread->priv;
1280 1278
1281 if (ttrace && fd >= 0 && fd <= ttrace->paths.max) { 1279 if (ttrace && fd >= 0 && fd <= ttrace->paths.max)
1282 free(ttrace->paths.table[fd]); 1280 zfree(&ttrace->paths.table[fd]);
1283 ttrace->paths.table[fd] = NULL;
1284 }
1285 1281
1286 return printed; 1282 return printed;
1287} 1283}
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 94223d404f43..d11541d4d7d7 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -256,8 +256,7 @@ int ui_browser__show(struct ui_browser *browser, const char *title,
256 __ui_browser__show_title(browser, title); 256 __ui_browser__show_title(browser, title);
257 257
258 browser->title = title; 258 browser->title = title;
259 free(browser->helpline); 259 zfree(&browser->helpline);
260 browser->helpline = NULL;
261 260
262 va_start(ap, helpline); 261 va_start(ap, helpline);
263 err = vasprintf(&browser->helpline, helpline, ap); 262 err = vasprintf(&browser->helpline, helpline, ap);
@@ -272,8 +271,7 @@ void ui_browser__hide(struct ui_browser *browser)
272{ 271{
273 pthread_mutex_lock(&ui__lock); 272 pthread_mutex_lock(&ui__lock);
274 ui_helpline__pop(); 273 ui_helpline__pop();
275 free(browser->helpline); 274 zfree(&browser->helpline);
276 browser->helpline = NULL;
277 pthread_mutex_unlock(&ui__lock); 275 pthread_mutex_unlock(&ui__lock);
278} 276}
279 277
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 0d9dd99507ee..022d1731b801 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1267,10 +1267,8 @@ static inline void free_popup_options(char **options, int n)
1267{ 1267{
1268 int i; 1268 int i;
1269 1269
1270 for (i = 0; i < n; ++i) { 1270 for (i = 0; i < n; ++i)
1271 free(options[i]); 1271 zfree(&options[i]);
1272 options[i] = NULL;
1273 }
1274} 1272}
1275 1273
1276/* Check whether the browser is for 'top' or 'report' */ 1274/* Check whether the browser is for 'top' or 'report' */
diff --git a/tools/perf/ui/gtk/util.c b/tools/perf/ui/gtk/util.c
index 696c1fbe4248..52e7fc48af9f 100644
--- a/tools/perf/ui/gtk/util.c
+++ b/tools/perf/ui/gtk/util.c
@@ -23,8 +23,7 @@ int perf_gtk__deactivate_context(struct perf_gtk_context **ctx)
23 if (!perf_gtk__is_active_context(*ctx)) 23 if (!perf_gtk__is_active_context(*ctx))
24 return -1; 24 return -1;
25 25
26 free(*ctx); 26 zfree(ctx);
27 *ctx = NULL;
28 return 0; 27 return 0;
29} 28}
30 29
diff --git a/tools/perf/util/alias.c b/tools/perf/util/alias.c
index e6d134773d0a..c0b43ee40d95 100644
--- a/tools/perf/util/alias.c
+++ b/tools/perf/util/alias.c
@@ -55,8 +55,7 @@ int split_cmdline(char *cmdline, const char ***argv)
55 src++; 55 src++;
56 c = cmdline[src]; 56 c = cmdline[src];
57 if (!c) { 57 if (!c) {
58 free(*argv); 58 zfree(argv);
59 *argv = NULL;
60 return error("cmdline ends with \\"); 59 return error("cmdline ends with \\");
61 } 60 }
62 } 61 }
@@ -68,8 +67,7 @@ int split_cmdline(char *cmdline, const char ***argv)
68 cmdline[dst] = 0; 67 cmdline[dst] = 0;
69 68
70 if (quoted) { 69 if (quoted) {
71 free(*argv); 70 zfree(argv);
72 *argv = NULL;
73 return error("unclosed quote"); 71 return error("unclosed quote");
74 } 72 }
75 73
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 27ab7b59dbf4..a78721d14694 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -185,8 +185,7 @@ static int lock__parse(struct ins_operands *ops)
185 return 0; 185 return 0;
186 186
187out_free_ops: 187out_free_ops:
188 free(ops->locked.ops); 188 zfree(&ops->locked.ops);
189 ops->locked.ops = NULL;
190 return 0; 189 return 0;
191} 190}
192 191
@@ -256,8 +255,7 @@ static int mov__parse(struct ins_operands *ops)
256 return 0; 255 return 0;
257 256
258out_free_source: 257out_free_source:
259 free(ops->source.raw); 258 zfree(&ops->source.raw);
260 ops->source.raw = NULL;
261 return -1; 259 return -1;
262} 260}
263 261
@@ -560,8 +558,7 @@ static int disasm_line__parse(char *line, char **namep, char **rawp)
560 return 0; 558 return 0;
561 559
562out_free_name: 560out_free_name:
563 free(*namep); 561 zfree(namep);
564 *namep = NULL;
565 return -1; 562 return -1;
566} 563}
567 564
@@ -1113,8 +1110,7 @@ static void symbol__free_source_line(struct symbol *sym, int len)
1113 src_line = (void *)src_line + sizeof_src_line; 1110 src_line = (void *)src_line + sizeof_src_line;
1114 } 1111 }
1115 1112
1116 free(notes->src->lines); 1113 zfree(&notes->src->lines);
1117 notes->src->lines = NULL;
1118} 1114}
1119 1115
1120/* Get the filename:line for the colored entries */ 1116/* Get the filename:line for the colored entries */
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 4ddeecb9ff85..4045d086d9d9 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -497,21 +497,18 @@ void dso__delete(struct dso *dso)
497 symbols__delete(&dso->symbols[i]); 497 symbols__delete(&dso->symbols[i]);
498 498
499 if (dso->short_name_allocated) { 499 if (dso->short_name_allocated) {
500 free((char *)dso->short_name); 500 zfree((char **)&dso->short_name);
501 dso->short_name = NULL;
502 dso->short_name_allocated = false; 501 dso->short_name_allocated = false;
503 } 502 }
504 503
505 if (dso->long_name_allocated) { 504 if (dso->long_name_allocated) {
506 free((char *)dso->long_name); 505 zfree((char **)&dso->long_name);
507 dso->long_name = NULL;
508 dso->long_name_allocated = false; 506 dso->long_name_allocated = false;
509 } 507 }
510 508
511 dso_cache__free(&dso->cache); 509 dso_cache__free(&dso->cache);
512 dso__free_a2l(dso); 510 dso__free_a2l(dso);
513 free(dso->symsrc_filename); 511 zfree(&dso->symsrc_filename);
514 dso->symsrc_filename = NULL;
515 free(dso); 512 free(dso);
516} 513}
517 514
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index da3182914984..b08a7ecdcea1 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -101,10 +101,8 @@ static void perf_evlist__purge(struct perf_evlist *evlist)
101 101
102void perf_evlist__exit(struct perf_evlist *evlist) 102void perf_evlist__exit(struct perf_evlist *evlist)
103{ 103{
104 free(evlist->mmap); 104 zfree(&evlist->mmap);
105 free(evlist->pollfd); 105 zfree(&evlist->pollfd);
106 evlist->mmap = NULL;
107 evlist->pollfd = NULL;
108} 106}
109 107
110void perf_evlist__delete(struct perf_evlist *evlist) 108void perf_evlist__delete(struct perf_evlist *evlist)
@@ -587,8 +585,7 @@ void perf_evlist__munmap(struct perf_evlist *evlist)
587 for (i = 0; i < evlist->nr_mmaps; i++) 585 for (i = 0; i < evlist->nr_mmaps; i++)
588 __perf_evlist__munmap(evlist, i); 586 __perf_evlist__munmap(evlist, i);
589 587
590 free(evlist->mmap); 588 zfree(&evlist->mmap);
591 evlist->mmap = NULL;
592} 589}
593 590
594static int perf_evlist__alloc_mmap(struct perf_evlist *evlist) 591static int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 6874e0485693..93b6031d5459 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -750,8 +750,7 @@ void perf_evsel__free_id(struct perf_evsel *evsel)
750{ 750{
751 xyarray__delete(evsel->sample_id); 751 xyarray__delete(evsel->sample_id);
752 evsel->sample_id = NULL; 752 evsel->sample_id = NULL;
753 free(evsel->id); 753 zfree(&evsel->id);
754 evsel->id = NULL;
755} 754}
756 755
757void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads) 756void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
@@ -1960,8 +1959,7 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
1960 evsel->attr.type = PERF_TYPE_SOFTWARE; 1959 evsel->attr.type = PERF_TYPE_SOFTWARE;
1961 evsel->attr.config = PERF_COUNT_SW_CPU_CLOCK; 1960 evsel->attr.config = PERF_COUNT_SW_CPU_CLOCK;
1962 1961
1963 free(evsel->name); 1962 zfree(&evsel->name);
1964 evsel->name = NULL;
1965 return true; 1963 return true;
1966 } 1964 }
1967 1965
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 10730b0af804..20f3a9c97bd8 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1324,8 +1324,7 @@ read_event_desc(struct perf_header *ph, int fd)
1324 } 1324 }
1325 } 1325 }
1326out: 1326out:
1327 if (buf) 1327 free(buf);
1328 free(buf);
1329 return events; 1328 return events;
1330error: 1329error:
1331 if (events) 1330 if (events)
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 8b1f6e891b8a..7b68978e50d2 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -263,9 +263,8 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
263 263
264 for (i = 0; i < old->cnt; i++) 264 for (i = 0; i < old->cnt; i++)
265 cmds->names[cmds->cnt++] = old->names[i]; 265 cmds->names[cmds->cnt++] = old->names[i];
266 free(old->names); 266 zfree(&old->names);
267 old->cnt = 0; 267 old->cnt = 0;
268 old->names = NULL;
269} 268}
270 269
271const char *help_unknown_cmd(const char *cmd) 270const char *help_unknown_cmd(const char *cmd)
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index c78cc84f433e..a98538dc465a 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -102,8 +102,7 @@ void machine__exit(struct machine *machine)
102 map_groups__exit(&machine->kmaps); 102 map_groups__exit(&machine->kmaps);
103 dsos__delete(&machine->user_dsos); 103 dsos__delete(&machine->user_dsos);
104 dsos__delete(&machine->kernel_dsos); 104 dsos__delete(&machine->kernel_dsos);
105 free(machine->root_dir); 105 zfree(&machine->root_dir);
106 machine->root_dir = NULL;
107} 106}
108 107
109void machine__delete(struct machine *machine) 108void machine__delete(struct machine *machine)
@@ -562,11 +561,10 @@ void machine__destroy_kernel_maps(struct machine *machine)
562 * on one of them. 561 * on one of them.
563 */ 562 */
564 if (type == MAP__FUNCTION) { 563 if (type == MAP__FUNCTION) {
565 free((char *)kmap->ref_reloc_sym->name); 564 zfree((char **)&kmap->ref_reloc_sym->name);
566 kmap->ref_reloc_sym->name = NULL; 565 zfree(&kmap->ref_reloc_sym);
567 free(kmap->ref_reloc_sym); 566 } else
568 } 567 kmap->ref_reloc_sym = NULL;
569 kmap->ref_reloc_sym = NULL;
570 } 568 }
571 569
572 map__delete(machine->vmlinux_maps[type]); 570 map__delete(machine->vmlinux_maps[type]);
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 095a98ec7444..4d3cd1a0278a 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -506,15 +506,13 @@ static int get_real_path(const char *raw_path, const char *comp_dir,
506 case EFAULT: 506 case EFAULT:
507 raw_path = strchr(++raw_path, '/'); 507 raw_path = strchr(++raw_path, '/');
508 if (!raw_path) { 508 if (!raw_path) {
509 free(*new_path); 509 zfree(new_path);
510 *new_path = NULL;
511 return -ENOENT; 510 return -ENOENT;
512 } 511 }
513 continue; 512 continue;
514 513
515 default: 514 default:
516 free(*new_path); 515 zfree(new_path);
517 *new_path = NULL;
518 return -errno; 516 return -errno;
519 } 517 }
520 } 518 }
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 8c087359b7ce..6d8796e38d7f 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -226,10 +226,8 @@ struct debuginfo *debuginfo__new(const char *path)
226 if (!dbg) 226 if (!dbg)
227 return NULL; 227 return NULL;
228 228
229 if (debuginfo__init_offline_dwarf(dbg, path) < 0) { 229 if (debuginfo__init_offline_dwarf(dbg, path) < 0)
230 free(dbg); 230 zfree(&dbg);
231 dbg = NULL;
232 }
233 231
234 return dbg; 232 return dbg;
235} 233}
@@ -241,10 +239,8 @@ struct debuginfo *debuginfo__new_online_kernel(unsigned long addr)
241 if (!dbg) 239 if (!dbg)
242 return NULL; 240 return NULL;
243 241
244 if (debuginfo__init_online_kernel_dwarf(dbg, (Dwarf_Addr)addr) < 0) { 242 if (debuginfo__init_online_kernel_dwarf(dbg, (Dwarf_Addr)addr) < 0)
245 free(dbg); 243 zfree(&dbg);
246 dbg = NULL;
247 }
248 244
249 return dbg; 245 return dbg;
250} 246}
@@ -1302,8 +1298,7 @@ int debuginfo__find_trace_events(struct debuginfo *dbg,
1302 1298
1303 ret = debuginfo__find_probes(dbg, &tf.pf); 1299 ret = debuginfo__find_probes(dbg, &tf.pf);
1304 if (ret < 0) { 1300 if (ret < 0) {
1305 free(*tevs); 1301 zfree(tevs);
1306 *tevs = NULL;
1307 return ret; 1302 return ret;
1308 } 1303 }
1309 1304
@@ -1417,8 +1412,7 @@ int debuginfo__find_available_vars_at(struct debuginfo *dbg,
1417 free(af.vls[af.nvls].point.symbol); 1412 free(af.vls[af.nvls].point.symbol);
1418 strlist__delete(af.vls[af.nvls].vars); 1413 strlist__delete(af.vls[af.nvls].vars);
1419 } 1414 }
1420 free(af.vls); 1415 zfree(vls);
1421 *vls = NULL;
1422 return ret; 1416 return ret;
1423 } 1417 }
1424 1418
@@ -1522,8 +1516,7 @@ post:
1522 if (fname) { 1516 if (fname) {
1523 ppt->file = strdup(fname); 1517 ppt->file = strdup(fname);
1524 if (ppt->file == NULL) { 1518 if (ppt->file == NULL) {
1525 free(ppt->function); 1519 zfree(&ppt->function);
1526 ppt->function = NULL;
1527 ret = -ENOMEM; 1520 ret = -ENOMEM;
1528 goto end; 1521 goto end;
1529 } 1522 }
@@ -1577,8 +1570,7 @@ static int find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf)
1577 else 1570 else
1578 ret = 0; /* Lines are not found */ 1571 ret = 0; /* Lines are not found */
1579 else { 1572 else {
1580 free(lf->lr->path); 1573 zfree(&lf->lr->path);
1581 lf->lr->path = NULL;
1582 } 1574 }
1583 return ret; 1575 return ret;
1584} 1576}
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 923d00040bbf..fd9e1a4fad16 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1621,13 +1621,10 @@ static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
1621 1621
1622static void vmlinux_path__exit(void) 1622static void vmlinux_path__exit(void)
1623{ 1623{
1624 while (--vmlinux_path__nr_entries >= 0) { 1624 while (--vmlinux_path__nr_entries >= 0)
1625 free(vmlinux_path[vmlinux_path__nr_entries]); 1625 zfree(&vmlinux_path[vmlinux_path__nr_entries]);
1626 vmlinux_path[vmlinux_path__nr_entries] = NULL;
1627 }
1628 1626
1629 free(vmlinux_path); 1627 zfree(&vmlinux_path);
1630 vmlinux_path = NULL;
1631} 1628}
1632 1629
1633static int vmlinux_path__init(void) 1630static int vmlinux_path__init(void)
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 9b5f856cc280..cf44644a4058 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -9,6 +9,7 @@
9#include "strlist.h" 9#include "strlist.h"
10#include <string.h> 10#include <string.h>
11#include "thread_map.h" 11#include "thread_map.h"
12#include "util.h"
12 13
13/* Skip "." and ".." directories */ 14/* Skip "." and ".." directories */
14static int filter(const struct dirent *dir) 15static int filter(const struct dirent *dir)
@@ -138,8 +139,7 @@ out_free_namelist:
138 free(namelist); 139 free(namelist);
139 140
140out_free_closedir: 141out_free_closedir:
141 free(threads); 142 zfree(&threads);
142 threads = NULL;
143 goto out_closedir; 143 goto out_closedir;
144} 144}
145 145
@@ -210,8 +210,7 @@ out_free_namelist:
210 free(namelist); 210 free(namelist);
211 211
212out_free_threads: 212out_free_threads:
213 free(threads); 213 zfree(&threads);
214 threads = NULL;
215 goto out; 214 goto out;
216} 215}
217 216
@@ -262,8 +261,7 @@ out:
262 return threads; 261 return threads;
263 262
264out_free_threads: 263out_free_threads:
265 free(threads); 264 zfree(&threads);
266 threads = NULL;
267 goto out; 265 goto out;
268} 266}
269 267
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index c354b95a2348..9f73bf43862c 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -562,10 +562,8 @@ out:
562 output_fd = fd; 562 output_fd = fd;
563 } 563 }
564 564
565 if (err) { 565 if (err)
566 free(tdata); 566 zfree(&tdata);
567 tdata = NULL;
568 }
569 567
570 put_tracepoints_path(tps); 568 put_tracepoints_path(tps);
571 return tdata; 569 return tdata;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 9a2c268ad718..6995d66f225c 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -186,6 +186,8 @@ static inline void *zalloc(size_t size)
186 return calloc(1, size); 186 return calloc(1, size);
187} 187}
188 188
189#define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
190
189static inline int has_extension(const char *filename, const char *ext) 191static inline int has_extension(const char *filename, const char *ext)
190{ 192{
191 size_t len = strlen(filename); 193 size_t len = strlen(filename);