Re: [PATCHv2 2/9] python: add API exports for virConnectListAllDomains()

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

 



On 06/05/2012 07:19 AM, Peter Krempa wrote:
> This patch adds export of the new API function
> virConnectListAllDomains() to the libvirt-python bindings. The
> virConnect object now has method "listAllDomains" that takes only the
> flags parameter and returns a python list of virDomain object
> corresponding to virDomainPtrs returned by the underlying api.
> 
> The implementation is done manually as the generator does not support
> wrapping list of virDomainPtrs into virDomain objects.
> ---
> No change to v1.
> ---
>  python/libvirt-override-api.xml       |   12 ++++++--
>  python/libvirt-override-virConnect.py |   12 ++++++++
>  python/libvirt-override.c             |   47 ++++++++++++++++++++++++++++++++-
>  3 files changed, 67 insertions(+), 4 deletions(-)
> 


> +    if (!(py_retval = PyList_New(c_retval)))
> +        goto cleanup;
> +
> +    for (i = 0; i < c_retval; i++) {
> +        if (PyList_SetItem(py_retval, i,
> +                           libvirt_virDomainPtrWrap(doms[i])) < 0) {

libvirt_virDomainPtrWrap() can return NULL on OOM; but PyList_SetItem()
cannot take a NULL argument.  You need to separate this into two steps
with an intermediate variable which you check for NULL.

if ((tmp = libvirt_virDomainPtrWrap(doms[i])) == NULL ||
    PyList_SetItem(py_retval, i, tmp) < 0) {

> +            Py_DECREF(py_retval);
> +            py_retval = NULL;

Likewise, to avoid a leak, you would need to add:

Py_XDECREF(tmp);

ACK with that fix.

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP 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]