From 94711ff79186fb58c5d10978a99ecf8ab035827d Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 31 Jul 2007 14:27:12 +0000 Subject: [PATCH] Fixed memory leaks --- ChangeLog | 5 +++++ src/qemu_conf.c | 6 ++++++ src/xml.c | 7 ++++++- tests/qemuxml2argvtest.c | 3 ++- tests/qemuxml2xmltest.c | 4 ++-- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8e609f5c51..3ea7f3119d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Jul 31 10:24:23 EST 2007 Daniel P. Berrange + + * src/qemu_conf.c, src/xml.c, tests/qemuxml2argvtest.c, + tests/qemuxml2xmltest.c: Fix a couple of memory leaks + Mon Jul 30 14:40:23 EST 2007 Daniel P. Berrange * src/qemu_conf.c: Validate requested architecture and reject diff --git a/src/qemu_conf.c b/src/qemu_conf.c index 4f88d21ca7..7219cf5b2e 100644 --- a/src/qemu_conf.c +++ b/src/qemu_conf.c @@ -135,6 +135,7 @@ struct qemud_network *qemudFindNetworkByName(const struct qemud_driver *driver, void qemudFreeVMDef(struct qemud_vm_def *def) { struct qemud_vm_disk_def *disk = def->disks; struct qemud_vm_net_def *net = def->nets; + struct qemud_vm_input_def *input = def->inputs; while (disk) { struct qemud_vm_disk_def *prev = disk; @@ -146,6 +147,11 @@ void qemudFreeVMDef(struct qemud_vm_def *def) { net = net->next; free(prev); } + while (input) { + struct qemud_vm_input_def *prev = input; + input = input->next; + free(prev); + } free(def); } diff --git a/src/xml.c b/src/xml.c index d202d502f7..b997ffe674 100644 --- a/src/xml.c +++ b/src/xml.c @@ -70,8 +70,11 @@ virXPathString(const char *xpath, xmlXPathContextPtr ctxt) { } obj = xmlXPathEval(BAD_CAST xpath, ctxt); if ((obj == NULL) || (obj->type != XPATH_STRING) || - (obj->stringval == NULL) || (obj->stringval[0] == 0)) + (obj->stringval == NULL) || (obj->stringval[0] == 0)) { + if (obj) + xmlXPathFreeObject(obj); return(NULL); + } ret = strdup((char *) obj->stringval); xmlXPathFreeObject(obj); if (ret == NULL) { @@ -618,6 +621,8 @@ virDomainParseXMLOSDescHVM(virConnectPtr conn, xmlNodePtr node, virBufferPtr buf if (str != NULL && !strcmp(str, "localtime")) { virBufferAdd(buf, "(localtime 1)", 13); } + if (str) + free(str); virBufferAdd(buf, "))", 2); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 6e77a21c5d..ea4b046588 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -22,7 +22,7 @@ static int testCompareXMLToArgvFiles(const char *xml, const char *cmd) { char **argv = NULL; char **tmp = NULL; int ret = -1, len; - struct qemud_vm_def *vmdef; + struct qemud_vm_def *vmdef = NULL; struct qemud_vm vm; if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) @@ -80,6 +80,7 @@ static int testCompareXMLToArgvFiles(const char *xml, const char *cmd) { free(argv); } + qemudFreeVMDef(vmdef); return ret; } diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 0895d84fe4..edfee05955 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -19,7 +19,7 @@ static int testCompareXMLToXMLFiles(const char *xml) { char *xmlPtr = &(xmlData[0]); char *actual = NULL; int ret = -1; - struct qemud_vm_def *vmdef; + struct qemud_vm_def *vmdef = NULL; struct qemud_vm vm; if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) @@ -48,7 +48,7 @@ static int testCompareXMLToXMLFiles(const char *xml) { fail: free(actual); - + qemudFreeVMDef(vmdef); return ret; } -- GitLab