Patchwork [6/8] x86/cpuid: Plug memory leak in cpudef_setfield()

login
register
mail settings
Submitter Stefan Hajnoczi
Date Nov. 10, 2011, 12:36 p.m.
Message ID <1320928604-6642-7-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/124860/
State New
Headers show

Comments

Stefan Hajnoczi - Nov. 10, 2011, 12:36 p.m.
From: Markus Armbruster <armbru@redhat.com>

To reproduce the leak, put two name options into the same [cpudef]
section of target-x86_64.conf.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 target-i386/cpuid.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

Patch

diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index 352c390..99cff65 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -950,6 +950,7 @@  static int cpudef_setfield(const char *name, const char *str, void *opaque)
     int err = 0;
 
     if (!strcmp(name, "name")) {
+        g_free((void *)def->name);
         def->name = g_strdup(str);
     } else if (!strcmp(name, "model_id")) {
         strncpy(def->model_id, str, sizeof (def->model_id));