perf session: Destructors should accept NULL
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 22 Jun 2016 13:02:16 +0000 (10:02 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 22 Jun 2016 13:02:16 +0000 (10:02 -0300)
And do nothing, just like free(), to avoid having to test it in callers,
usually in error paths.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-dyuupcj0hnoyt96vma8b3anv@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-buildid-cache.c
tools/perf/builtin-diff.c
tools/perf/builtin-kvm.c
tools/perf/util/session.c

index d75bded21fe0ce73ef9aea745ff565c9ba61a204..2cbec658be90a6daf57b4596ac2375f345f4f147 100644 (file)
@@ -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;
 }
index 8b6735f3517937b85eb6e4909c483adbb75a6fb0..eac0b1100b8fd0d6da921ef92f6c35c4c5b32080 100644 (file)
@@ -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);
        }
 
index ad46e91abec5444f4e61b8bd7203c7206ed426a4..8f8f90e2b993660f6c9f4f470e83338c51259576 100644 (file)
@@ -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);
 
index dfedf097b9b1ffdafd4b6380a8bd4fe68e58ad62..43be0c5a6a268a44a2b20b4bf82e87e1a12c7067 100644 (file)
@@ -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);