Fix leak of comment string if virConfAddEntry fails on OOM

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>
This commit is contained in:
Daniel P. Berrange 2013-09-25 11:32:07 +01:00
parent 1f66001c69
commit a8412f868b

View File

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