Re: [PATCHv3 7/7] xen_common: Fix a few memory leaks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux