From 8af1c9cb6c4fd2867c248de192f91bec1fb1def9 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Tue, 29 Sep 2015 21:59:41 +0200 Subject: Must check return value for all Py*_New functions If the function fails, we need to cleanup memory and return NULL. Signed-off-by: Pavel Hrdina --- libvirt-lxc-override.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'libvirt-lxc-override.c') diff --git a/libvirt-lxc-override.c b/libvirt-lxc-override.c index 20d1cf4..b0550c7 100644 --- a/libvirt-lxc-override.c +++ b/libvirt-lxc-override.c @@ -79,7 +79,9 @@ libvirt_lxc_virDomainLxcOpenNamespace(PyObject *self ATTRIBUTE_UNUSED, if (c_retval < 0) return VIR_PY_NONE; - py_retval = PyList_New(0); + if ((py_retval = PyList_New(0)) == NULL) + goto error; + for (i = 0; i < c_retval; i++) { PyObject *item = NULL; @@ -91,6 +93,8 @@ libvirt_lxc_virDomainLxcOpenNamespace(PyObject *self ATTRIBUTE_UNUSED, goto error; } } + + cleanup: VIR_FREE(fdlist); return py_retval; @@ -98,8 +102,8 @@ libvirt_lxc_virDomainLxcOpenNamespace(PyObject *self ATTRIBUTE_UNUSED, for (i = 0; i < c_retval; i++) { VIR_FORCE_CLOSE(fdlist[i]); } - VIR_FREE(fdlist); - return NULL; + Py_CLEAR(py_retval); + goto cleanup; } /************************************************************************ * * -- cgit v1.2.1