[libvirt] [PATCH 2/2] python: add error checking for calls to PyList_New

Martin Kletzander mkletzan at redhat.com
Tue Nov 12 13:53:29 UTC 2013


On Thu, Nov 07, 2013 at 03:44:23PM +0100, Giuseppe Scrivano wrote:
> Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
> ---
>  python/libvirt-override.c | 88 +++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 70 insertions(+), 18 deletions(-)
> 
> diff --git a/python/libvirt-override.c b/python/libvirt-override.c
> index 83bca94..3b902bc 100644
> --- a/python/libvirt-override.c
> +++ b/python/libvirt-override.c
[...]
> @@ -2621,7 +2630,8 @@ libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
>              return VIR_PY_NONE;
>          }
>      }
> -    py_retval = PyList_New(c_retval);
> +    if (!(py_retval = PyList_New(c_retval)))
> +        goto cleanup;
>  

This function should follow others and return VIR_PY_NONE, but cleanup
path returns py_retval.

>      for (i = 0; i < c_retval; i++) {
>          if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL) {
[...]
> @@ -3207,11 +3235,14 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg
>          VIR_FREE(freeMems);
>          return VIR_PY_NONE;
>      }
> -    py_retval = PyList_New(c_retval);
> +    if (!(py_retval = PyList_New(c_retval)))
> +        goto cleanup;
> +

ditto

>      for (i = 0; i < c_retval; i++) {
>          PyList_SET_ITEM(py_retval, i,
>                  libvirt_longlongWrap((long long) freeMems[i]));
>      }
> +cleanup:
>      VIR_FREE(freeMems);
>      return py_retval;
>  }

ACK with those two places fixed (don't forget to free the names in a
loop in the first hunk).

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20131112/4b1dc2c3/attachment-0001.sig>


More information about the libvir-list mailing list