Patchwork [2/3] x86/cpuid: Plug memory leak in cpudef_setfield()

login
register
mail settings
Submitter Markus Armbruster
Date Nov. 8, 2011, 2:36 p.m.
Message ID <1320763010-10024-3-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/124384/
State New
Headers show

Comments

Markus Armbruster - Nov. 8, 2011, 2:36 p.m.
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>
---
 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 7c8f1be..0fce752 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -969,6 +969,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));