[libvirt] [PATCH 09/23] Fix leak of comment string if virConfAddEntry fails on OOM

Daniel P. Berrange berrange at redhat.com
Wed Sep 25 14:51:04 UTC 2013


From: "Daniel P. Berrange" <berrange at redhat.com>

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 at redhat.com>
---
 src/util/virconf.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/util/virconf.c b/src/util/virconf.c
index 9952f3f..e882d15 100644
--- a/src/util/virconf.c
+++ b/src/util/virconf.c
@@ -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;
 }
 
-- 
1.8.3.1




More information about the libvir-list mailing list