Re: [PATCH v2 5/5] cpu_models: add Python bindings

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

 



On 09/06/2013 05:11 PM, Giuseppe Scrivano wrote:
> Signed-off-by: Giuseppe Scrivano <gscrivan@xxxxxxxxxx>
> ---
>  python/generator.py             |  2 +-
>  python/libvirt-override-api.xml |  7 ++++++
>  python/libvirt-override.c       | 56 +++++++++++++++++++++++++++++++++++++++++
>  python/libvirt-override.py      | 11 ++++++++
>  4 files changed, 75 insertions(+), 1 deletion(-)


> +
> +    len = 0;
> +    for (it = models; *it; it++)
> +        len++;
> +
> +    if ((rv = PyList_New(len)) == NULL)
> +        goto error;
> +

Again, the C return value should make it so you don't have to re-count
len via 'it' yourself.

> +    len = 0;
> +    for (it = models; *it; it++){

Space before {

> +        PyObject *str;
> +        if ((str = PyString_FromString(*it)) == NULL)
> +            goto error;
> +
> +        PyList_SET_ITEM(rv, len++, str);
> +    }
> +
> +done:
> +    if (models) {
> +        for (it = models; *it; it++)
> +            VIR_FREE(*it);
> +        VIR_FREE(models);
> +    }
> +
> +    return rv;
> +
> +error:
> +    rv = VIR_PY_INT_FAIL;

Ouch.  Memory leak of the former value of rv.

-- 
Eric Blake   eblake redhat com    +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]