Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion perf kvm: handle realloc failures
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David Ahern  
View profile  
 More options Oct 8 2012, 1:20 pm
Newsgroups: linux.kernel
From: David Ahern <dsah...@gmail.com>
Date: Mon, 08 Oct 2012 19:20:02 +0200
Local: Mon, Oct 8 2012 1:20 pm
Subject: [PATCH 07/12] perf kvm: handle realloc failures
Save previous pointer and free on failure.

Signed-off-by: David Ahern <dsah...@gmail.com>
Cc: Arnaldo Carvalho de Melo <a...@ghostprotocols.net>
Cc: Ingo Molnar <mi...@kernel.org>
Cc: Frederic Weisbecker <fweis...@gmail.com>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Xiao Guangrong <xiaoguangr...@linux.vnet.ibm.com>
Cc: Dong Hao <haod...@linux.vnet.ibm.com>
---
 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 a23db89..af74a97 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -327,6 +327,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;
@@ -334,9 +335,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;
        }
--
1.7.10.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.