perf evlist: Destructors should accept NULL
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 21 Jun 2016 21:15:45 +0000 (18:15 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 22 Jun 2016 13:01:48 +0000 (10:01 -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-mexbavy0ft387j5w89t365eu@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-kvm.c
tools/perf/tests/event-times.c
tools/perf/tests/parse-no-sample-id-all.c
tools/perf/util/evlist.c

index 6487c06d270853fdf3c0e3a101f821d5692871a6..ad46e91abec5444f4e61b8bd7203c7206ed426a4 100644 (file)
@@ -1429,8 +1429,7 @@ out:
        if (kvm->session)
                perf_session__delete(kvm->session);
        kvm->session = NULL;
-       if (kvm->evlist)
-               perf_evlist__delete(kvm->evlist);
+       perf_evlist__delete(kvm->evlist);
 
        return err;
 }
index 95fb744f6628b46301163f24fe5679d46c192453..9f5698ac81ae2373461db58d40a2e742712b96bc 100644 (file)
@@ -200,8 +200,7 @@ static int test_times(int (attach)(struct perf_evlist *),
                 count.ena, count.run);
 
 out_err:
-       if (evlist)
-               perf_evlist__delete(evlist);
+       perf_evlist__delete(evlist);
        return !err ? TEST_OK : TEST_FAIL;
 }
 
index 294c76b01b417d004fd20c047b624fe04cf61f65..81c6eeaca0f53ec00d9cabca4d13119856b0c719 100644 (file)
@@ -44,8 +44,7 @@ static int process_events(union perf_event **events, size_t count)
        for (i = 0; i < count && !err; i++)
                err = process_event(&evlist, events[i]);
 
-       if (evlist)
-               perf_evlist__delete(evlist);
+       perf_evlist__delete(evlist);
 
        return err;
 }
index 1b918aa075d6a13a2f9cf07784c6f3285f90f45f..fcb8f1ff7806df347424b6f59d288d3df23859cb 100644 (file)
@@ -127,6 +127,9 @@ void perf_evlist__exit(struct perf_evlist *evlist)
 
 void perf_evlist__delete(struct perf_evlist *evlist)
 {
+       if (evlist == NULL)
+               return;
+
        perf_evlist__munmap(evlist);
        perf_evlist__close(evlist);
        cpu_map__put(evlist->cpus);