Skip to contentSkip to conversation

perf machine: Destructors should accept NULL

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Jun 26, 2016 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  32ca678dcd250f05183cf0c8a9e516545c6068bc
Gitweb:     http://git.kernel.org/tip/32ca678dcd250f05183cf0c8a9e516545c6068bc
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Wed, 22 Jun 2016 10:19:11 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 22 Jun 2016 10:19:11 -0300

perf machine: Destructors should accept NULL

And do nothing, just like free(), to avoid having to test it in callers, usually in error paths.

---
 tools/perf/util/machine.c     | 6 ++++--
 tools/perf/util/probe-event.c | 6 ++----
 2 files changed, 6 insertions(+), 6 deletions(-)
tools/perf/util/machine.c +4 -2
index a0c186a..bc2cdbd 100644
@@ -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)
tools/perf/util/probe-event.c +2 -4
index 084756c..caad19d 100644
@@ -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();
 }