perf kvm: Fill in the missing session freeing after an error occurs
authorTaeung Song <treeze.taeung@gmail.com>
Tue, 30 Jun 2015 15:18:44 +0000 (00:18 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 1 Jul 2015 20:53:49 +0000 (17:53 -0300)
When an error occurs an error value is just returned without freeing the
session. So allocating and freeing session have to be matched as a pair
even if an error occurs.

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1435677525-28055-1-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-kvm.c

index 74878cd75078055e437396fc9a6b201603586076..fc1cffb1b7a28c9b0d9856770530a0e8b3bf9606 100644 (file)
@@ -1061,8 +1061,10 @@ static int read_events(struct perf_kvm_stat *kvm)
 
        symbol__init(&kvm->session->header.env);
 
-       if (!perf_session__has_traces(kvm->session, "kvm record"))
-               return -EINVAL;
+       if (!perf_session__has_traces(kvm->session, "kvm record")) {
+               ret = -EINVAL;
+               goto out_delete;
+       }
 
        /*
         * Do not use 'isa' recorded in kvm_exit tracepoint since it is not
@@ -1070,9 +1072,13 @@ static int read_events(struct perf_kvm_stat *kvm)
         */
        ret = cpu_isa_config(kvm);
        if (ret < 0)
-               return ret;
+               goto out_delete;
 
-       return perf_session__process_events(kvm->session);
+       ret = perf_session__process_events(kvm->session);
+
+out_delete:
+       perf_session__delete(kvm->session);
+       return ret;
 }
 
 static int parse_target_str(struct perf_kvm_stat *kvm)