[PATCH 10/27] perf session: Destructors should accept NULL
From: Arnaldo Carvalho de Melo
Date: Thu Jun 23 2016 - 17:28:15 EST
From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
And do nothing, just like free(), to avoid having to test it in callers,
usually in error paths.
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Wang Nan <wangnan0@xxxxxxxxxx>
Link: http://lkml.kernel.org/n/tip-dyuupcj0hnoyt96vma8b3anv@xxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/builtin-buildid-cache.c | 3 +--
tools/perf/builtin-diff.c | 4 +---
tools/perf/builtin-kvm.c | 3 +--
tools/perf/util/session.c | 2 ++
4 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index d75bded21fe0..2cbec658be90 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -419,8 +419,7 @@ int cmd_buildid_cache(int argc, const char **argv,
pr_warning("Couldn't add %s\n", kcore_filename);
out:
- if (session)
- perf_session__delete(session);
+ perf_session__delete(session);
return ret;
}
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 8b6735f35179..eac0b1100b8f 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -756,9 +756,7 @@ static int __cmd_diff(void)
out_delete:
data__for_each_file(i, d) {
- if (d->session)
- perf_session__delete(d->session);
-
+ perf_session__delete(d->session);
data__free(d);
}
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index ad46e91abec5..8f8f90e2b993 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1426,8 +1426,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
err = kvm_events_live_report(kvm);
out:
- if (kvm->session)
- perf_session__delete(kvm->session);
+ perf_session__delete(kvm->session);
kvm->session = NULL;
perf_evlist__delete(kvm->evlist);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index dfedf097b9b1..43be0c5a6a26 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -178,6 +178,8 @@ static void perf_session__delete_threads(struct perf_session *session)
void perf_session__delete(struct perf_session *session)
{
+ if (session == NULL)
+ return;
auxtrace__free(session);
auxtrace_index__free(&session->auxtrace_index);
perf_session__destroy_kernel_maps(session);
--
2.5.5