On Mon, May 28, 2018 at 12:28:26AM +0200, Fabiano Fidêncio wrote:
While converting the functions of xen_common to use typesafe virConf acessors, I've spotted a few memory leaks, which are fixed in this patch. Signed-off-by: Fabiano Fidêncio <fabiano@xxxxxxxxxxxx> --- src/xenconfig/xen_common.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 2ba1a19c39..6d9ce9bd66 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -458,14 +458,16 @@ xenParsePCIList(virConfPtr conf, virDomainDefPtr def) for (entries = pcis; *entries; entries++) { char *entry = *entries; virDomainHostdevDefPtr hostdev; + int rc; if (!(hostdev = xenParsePCI(entry))) goto cleanup; - if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0) { - virDomainHostdevDefFree(hostdev); + rc = VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev); + virDomainHostdevDefFree(hostdev); +
If VIR_APPEND_ELEMENT returns 0, hostdev has been added to the domain definition and it should be freed by whoever frees the virDomainDef. Also, on success the arguments of VIR_APPEND_ELEMENT are zeroed, so this change is a no-op. Jano
Attachment:
signature.asc
Description: Digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list