]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix leak of comment string if virConfAddEntry fails on OOM
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 25 Sep 2013 10:32:07 +0000 (11:32 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 25 Sep 2013 17:12:09 +0000 (18:12 +0100)
The code parsing comments in config files called virConfAddEntry
but did not check for failure. This caused the comment string to
leak on OOM.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/util/virconf.c

index 9952f3fee0a2bf46623b1cf0f60203d1629ab380..e882d150752cc813fdb56f56f6ef8543fad1148d 100644 (file)
@@ -589,7 +589,10 @@ virConfParseComment(virConfParserCtxtPtr ctxt)
     while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT;
     if (VIR_STRNDUP(comm, base, ctxt->cur - base) < 0)
         return -1;
-    virConfAddEntry(ctxt->conf, NULL, NULL, comm);
+    if (virConfAddEntry(ctxt->conf, NULL, NULL, comm) == NULL) {
+        VIR_FREE(comm);
+        return -1;
+    }
     return 0;
 }