Commit-ID:  6ca5f3081f903e2b25e58a061ddad486f846561e
Gitweb:     http://git.kernel.org/tip/6ca5f3081f903e2b25e58a061ddad486f846561e
Author:     David Ahern <[email protected]>
AuthorDate: Sat, 25 May 2013 18:24:46 -0600
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 28 May 2013 16:24:04 +0300

perf kvm: Handle realloc failures

Save previous pointer and free on failure.

Signed-off-by: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Runzhen Wang <[email protected]>
Cc: Xiao Guangrong <[email protected]>
Link: 
http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/builtin-kvm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 533501e..24b78ae 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -328,6 +328,7 @@ static int kvm_events_hash_fn(u64 key)
 static bool kvm_event_expand(struct kvm_event *event, int vcpu_id)
 {
        int old_max_vcpu = event->max_vcpu;
+       void *prev;
 
        if (vcpu_id < event->max_vcpu)
                return true;
@@ -335,9 +336,11 @@ static bool kvm_event_expand(struct kvm_event *event, int 
vcpu_id)
        while (event->max_vcpu <= vcpu_id)
                event->max_vcpu += DEFAULT_VCPU_NUM;
 
+       prev = event->vcpu;
        event->vcpu = realloc(event->vcpu,
                              event->max_vcpu * sizeof(*event->vcpu));
        if (!event->vcpu) {
+               free(prev);
                pr_err("Not enough memory\n");
                return false;
        }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to