diff options
author | David Ahern <dsahern@gmail.com> | 2013-05-25 20:24:46 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-05-28 09:24:04 -0400 |
commit | 6ca5f3081f903e2b25e58a061ddad486f846561e (patch) | |
tree | 10ba490bc80b175c410569fa0c33b745b797c255 /tools/perf/builtin-kvm.c | |
parent | b69e63a45f2d96a0dfe930ed20385058d4574d2f (diff) |
perf kvm: Handle realloc failures
Save previous pointer and free on failure.
Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Runzhen Wang <runzhen@linux.vnet.ibm.com>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1369527896-3650-7-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-kvm.c')
-rw-r--r-- | tools/perf/builtin-kvm.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 533501e2b07c..24b78aecc928 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) | |||
328 | static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) | 328 | static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) |
329 | { | 329 | { |
330 | int old_max_vcpu = event->max_vcpu; | 330 | int old_max_vcpu = event->max_vcpu; |
331 | void *prev; | ||
331 | 332 | ||
332 | if (vcpu_id < event->max_vcpu) | 333 | if (vcpu_id < event->max_vcpu) |
333 | return true; | 334 | return true; |
@@ -335,9 +336,11 @@ static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) | |||
335 | while (event->max_vcpu <= vcpu_id) | 336 | while (event->max_vcpu <= vcpu_id) |
336 | event->max_vcpu += DEFAULT_VCPU_NUM; | 337 | event->max_vcpu += DEFAULT_VCPU_NUM; |
337 | 338 | ||
339 | prev = event->vcpu; | ||
338 | event->vcpu = realloc(event->vcpu, | 340 | event->vcpu = realloc(event->vcpu, |
339 | event->max_vcpu * sizeof(*event->vcpu)); | 341 | event->max_vcpu * sizeof(*event->vcpu)); |
340 | if (!event->vcpu) { | 342 | if (!event->vcpu) { |
343 | free(prev); | ||
341 | pr_err("Not enough memory\n"); | 344 | pr_err("Not enough memory\n"); |
342 | return false; | 345 | return false; |
343 | } | 346 | } |