perf machine: Destructors should accept NULL
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 22 Jun 2016 13:19:11 +0000 (10:19 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 22 Jun 2016 13:19:11 +0000 (10:19 -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-q42gj3b3znhho9z1mrbo4jce@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/machine.c
tools/perf/util/probe-event.c

index a0c186acb1f3ee5b9be6c8878cb74bd181a77644..bc2cdbd09a253078e99037fcb189737273e7f33a 100644 (file)
@@ -138,8 +138,10 @@ void machine__exit(struct machine *machine)
 
 void machine__delete(struct machine *machine)
 {
-       machine__exit(machine);
-       free(machine);
+       if (machine) {
+               machine__exit(machine);
+               free(machine);
+       }
 }
 
 void machines__init(struct machines *machines)
index 084756c173094c53e393b5f999968f9ade2a13a2..caad19d8c7ef9c451b76d15e9e8b36e5c7261f6b 100644 (file)
@@ -102,10 +102,8 @@ out:
 
 void exit_probe_symbol_maps(void)
 {
-       if (host_machine) {
-               machine__delete(host_machine);
-               host_machine = NULL;
-       }
+       machine__delete(host_machine);
+       host_machine = NULL;
        symbol__exit();
 }