[libvirt] [PATCHv3 7/7] xen_common: Fix a few memory leaks
Ján Tomko
jtomko at redhat.com
Mon Jun 11 13:30:09 UTC 2018
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 at fidencio.org>
>---
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180611/bb3750b2/attachment-0001.sig>
More information about the libvir-list
mailing list