[libvirt] [PATCH] plug two leaks

Running "make check" under valgrind exposed at least the first. Then, I spotted the other. * src/qemu_conf.c (qemudParseXML): Free "obj" unconditionally. --- src/qemu_conf.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu_conf.c b/src/qemu_conf.c index ff7c63e..47d49a2 100644 --- a/src/qemu_conf.c +++ b/src/qemu_conf.c @@ -1716,11 +1716,11 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn, (obj->stringval != NULL) && (obj->stringval[0] != 0)) { strncpy(def->os.bootloader, (const char*)obj->stringval, sizeof(def->os.bootloader)); NUL_TERMINATE(def->os.bootloader); - xmlXPathFreeObject(obj); /* Set a default OS type, since <type> is optional with bootloader */ strcpy(def->os.type, "xen"); } + xmlXPathFreeObject(obj); /* Extract OS type info */ obj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1])", ctxt); @@ -1733,9 +1733,9 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn, } } else { strcpy(def->os.type, (const char *)obj->stringval); - xmlXPathFreeObject(obj); - obj = NULL; } + xmlXPathFreeObject(obj); + obj = NULL; if (!virCapabilitiesSupportsGuestOSType(driver->caps, def->os.type)) { qemudReportError(conn, NULL, NULL, VIR_ERR_OS_TYPE, -- 1.5.5.1.249.g26848

On Fri, May 16, 2008 at 06:44:48PM +0200, Jim Meyering wrote:
Running "make check" under valgrind exposed at least the first. Then, I spotted the other.
ACK. Dan. -- |: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

"Daniel P. Berrange" <berrange@redhat.com> wrote:
On Fri, May 16, 2008 at 06:44:48PM +0200, Jim Meyering wrote:
Running "make check" under valgrind exposed at least the first. Then, I spotted the other.
ACK.
speedy ;-) Committed. Actually there's one more, but I don't have time for it right now: 128 (96 direct, 32 indirect) bytes in 6 blocks are definitely lost in loss record 5 of 7 at 0x4A05174: calloc (vg_replace_malloc.c:397) by 0x40A6EA: qemudParseVMDef (qemu_conf.c:2078) by 0x402991: testCompareXMLToArgvHelper (qemuxml2argvtest.c:43) by 0x4032C0: virtTestRun (testutils.c:79) by 0x402861: main (qemuxml2argvtest.c:180) It's allocated with this calloc call: /* Parse sound driver xml */ obj = xmlXPathEval(BAD_CAST "/domain/devices/sound", ctxt); if ((obj != NULL) && (obj->type == XPATH_NODESET) && (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { struct qemud_vm_sound_def *prev = NULL; for (i = 0; i < obj->nodesetval->nodeNr; i++) { struct qemud_vm_sound_def *sound = calloc(1, sizeof(*sound)); struct qemud_vm_sound_def *check = def->sounds; int collision = 0; if (!sound) { qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "%s", _("failed to allocate space for sound dev")); goto error; } if (qemudParseSoundXML(conn, sound, obj->nodesetval->nodeTab[i]) < 0) { free(sound); goto error; } // Check that model type isn't already present in sound dev list while(check) { if (check->model == sound->model) { collision = 1; break; } check = check->next; } if (collision) continue; def->nsounds++; sound->next = NULL; if (def->sounds == NULL) { def->sounds = sound; } else { prev->next = sound; } prev = sound; } }
participants (2)
-
Daniel P. Berrange
-
Jim Meyering