Skip to content

Commit

Permalink
perf tools: No need to test against NULL before calling free()
Browse files Browse the repository at this point in the history
Its perfectly fine to call free(NULL), so no need to clutter the source
code with all those superfluous testing.

Cc: Adrian Hunter <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Dec 26, 2013
1 parent 6dd6013 commit f538565
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 62 deletions.
4 changes: 1 addition & 3 deletions tools/perf/builtin-kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1158,9 +1158,7 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
if (kvm->timerfd >= 0)
close(kvm->timerfd);

if (pollfds)
free(pollfds);

free(pollfds);
return err;
}

Expand Down
3 changes: 1 addition & 2 deletions tools/perf/ui/browsers/scripts.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ int script_browse(const char *script_opt)
if (script.b.width > AVERAGE_LINE_LEN)
script.b.width = AVERAGE_LINE_LEN;

if (line)
free(line);
free(line);
pclose(fp);

script.nr_lines = nr_entries;
Expand Down
6 changes: 2 additions & 4 deletions tools/perf/util/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,10 +1232,8 @@ static void free_event_desc(struct perf_evsel *events)
return;

for (evsel = events; evsel->attr.size; evsel++) {
if (evsel->name)
free(evsel->name);
if (evsel->id)
free(evsel->id);
free(evsel->name);
free(evsel->id);
}

free(events);
Expand Down
62 changes: 21 additions & 41 deletions tools/perf/util/probe-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,7 @@ static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
}
}

if (tmp)
free(tmp);

free(tmp);
return ret;
}

Expand Down Expand Up @@ -1382,8 +1380,7 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
error:
pr_debug("Failed to synthesize perf probe point: %s\n",
strerror(-ret));
if (buf)
free(buf);
free(buf);
return NULL;
}

Expand Down Expand Up @@ -1584,34 +1581,25 @@ void clear_perf_probe_event(struct perf_probe_event *pev)
struct perf_probe_arg_field *field, *next;
int i;

if (pev->event)
free(pev->event);
if (pev->group)
free(pev->group);
if (pp->file)
free(pp->file);
if (pp->function)
free(pp->function);
if (pp->lazy_line)
free(pp->lazy_line);
free(pev->event);
free(pev->group);
free(pp->file);
free(pp->function);
free(pp->lazy_line);

for (i = 0; i < pev->nargs; i++) {
if (pev->args[i].name)
free(pev->args[i].name);
if (pev->args[i].var)
free(pev->args[i].var);
if (pev->args[i].type)
free(pev->args[i].type);
free(pev->args[i].name);
free(pev->args[i].var);
free(pev->args[i].type);
field = pev->args[i].field;
while (field) {
next = field->next;
if (field->name)
free(field->name);
free(field->name);
free(field);
field = next;
}
}
if (pev->args)
free(pev->args);
free(pev->args);
memset(pev, 0, sizeof(*pev));
}

Expand All @@ -1620,30 +1608,22 @@ static void clear_probe_trace_event(struct probe_trace_event *tev)
struct probe_trace_arg_ref *ref, *next;
int i;

if (tev->event)
free(tev->event);
if (tev->group)
free(tev->group);
if (tev->point.symbol)
free(tev->point.symbol);
if (tev->point.module)
free(tev->point.module);
free(tev->event);
free(tev->group);
free(tev->point.symbol);
free(tev->point.module);
for (i = 0; i < tev->nargs; i++) {
if (tev->args[i].name)
free(tev->args[i].name);
if (tev->args[i].value)
free(tev->args[i].value);
if (tev->args[i].type)
free(tev->args[i].type);
free(tev->args[i].name);
free(tev->args[i].value);
free(tev->args[i].type);
ref = tev->args[i].ref;
while (ref) {
next = ref->next;
free(ref);
ref = next;
}
}
if (tev->args)
free(tev->args);
free(tev->args);
memset(tev, 0, sizeof(*tev));
}

Expand Down
12 changes: 4 additions & 8 deletions tools/perf/util/probe-finder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1414,10 +1414,8 @@ int debuginfo__find_available_vars_at(struct debuginfo *dbg,
if (ret < 0) {
/* Free vlist for error */
while (af.nvls--) {
if (af.vls[af.nvls].point.symbol)
free(af.vls[af.nvls].point.symbol);
if (af.vls[af.nvls].vars)
strlist__delete(af.vls[af.nvls].vars);
free(af.vls[af.nvls].point.symbol);
strlist__delete(af.vls[af.nvls].vars);
}
free(af.vls);
*vls = NULL;
Expand Down Expand Up @@ -1524,10 +1522,8 @@ int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,
if (fname) {
ppt->file = strdup(fname);
if (ppt->file == NULL) {
if (ppt->function) {
free(ppt->function);
ppt->function = NULL;
}
free(ppt->function);
ppt->function = NULL;
ret = -ENOMEM;
goto end;
}
Expand Down
3 changes: 1 addition & 2 deletions tools/perf/util/scripting-engines/trace-event-perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ static void define_event_symbols(struct event_format *event,
zero_flag_atom = 0;
break;
case PRINT_FIELD:
if (cur_field_name)
free(cur_field_name);
free(cur_field_name);
cur_field_name = strdup(args->field.name);
break;
case PRINT_FLAGS:
Expand Down
3 changes: 1 addition & 2 deletions tools/perf/util/scripting-engines/trace-event-python.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ static void define_event_symbols(struct event_format *event,
zero_flag_atom = 0;
break;
case PRINT_FIELD:
if (cur_field_name)
free(cur_field_name);
free(cur_field_name);
cur_field_name = strdup(args->field.name);
break;
case PRINT_FLAGS:
Expand Down

0 comments on commit f538565

Please sign in to comment.