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

Eric Blake eblake at redhat.com
Tue Jun 5 18:01:41 UTC 2012


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 at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120605/0be5e2bf/attachment-0001.sig>


More information about the libvir-list mailing list