Re: [libvirt] [PATCH] Fix a memory leak in virsh.

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

 



On Sun, Aug 30, 2009 at 03:59:08PM -0400, Laine Stump wrote:
> 
> I found this while looking for examples of using
> virNodeDeviceGetXMLDesc(). AFAIK, *all* of the *GetXMLDesc() functions
> return a newly allocated chunk of memory that is owned by the caller,
> who must free it when they're done...

Yes, that is correct.


>  src/virsh.c |   10 +++++++++-
>  1 files changed, 9 insertions(+), 1 deletions(-)
> 
> diff --git a/src/virsh.c b/src/virsh.c
> index 15e0cef..910d860 100644
> --- a/src/virsh.c
> +++ b/src/virsh.c
> @@ -5521,6 +5521,7 @@ cmdNodeDeviceDumpXML (vshControl *ctl, const vshCmd *cmd)
>  {
>      const char *name;
>      virNodeDevicePtr device;
> +    char *xml;
>  
>      if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
>          return FALSE;
> @@ -5531,7 +5532,14 @@ cmdNodeDeviceDumpXML (vshControl *ctl, const vshCmd *cmd)
>          return FALSE;
>      }
>  
> -    vshPrint(ctl, "%s\n", virNodeDeviceGetXMLDesc(device, 0));
> +    xml = virNodeDeviceGetXMLDesc(device, 0);
> +    if (!xml) {
> +        virNodeDeviceFree(device);
> +        return FALSE;
> +    }
> +
> +    vshPrint(ctl, "%s\n", xml);
> +    free(xml);
>      virNodeDeviceFree(device);
>      return TRUE;
>  }

ACK

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
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]