perf tools: No need to test against NULL before calling free()

Its perfectly fine to call free(NULL), so no need to clutter the source
code with all those superfluous testing.

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-uux5wpvevlerd42gqer13e7n@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2013-12-26 15:54:57 -03:00
parent 6dd601354f
commit f5385650c0
7 changed files with 31 additions and 62 deletions

View File

@ -1158,9 +1158,7 @@ out:
if (kvm->timerfd >= 0)
close(kvm->timerfd);
if (pollfds)
free(pollfds);
free(pollfds);
return err;
}

View File

@ -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;

View File

@ -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);

View File

@ -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;
}
@ -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;
}
@ -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));
}
@ -1620,21 +1608,14 @@ 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;
@ -1642,8 +1623,7 @@ static void clear_probe_trace_event(struct probe_trace_event *tev)
ref = next;
}
}
if (tev->args)
free(tev->args);
free(tev->args);
memset(tev, 0, sizeof(*tev));
}

View File

@ -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;
@ -1524,10 +1522,8 @@ post:
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;
}

View File

@ -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:

View File

@ -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: