[libvirt] [python PATCH 2/4] typewrappers: Fix libvirt_charPtrUnwrap to set an exception if it fails

Pavel Hrdina phrdina at redhat.com
Tue Jun 12 05:16:39 UTC 2018


If the function fails it should always set an exception.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 typewrappers.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/typewrappers.c b/typewrappers.c
index 01ee310..99a8fb8 100644
--- a/typewrappers.c
+++ b/typewrappers.c
@@ -384,8 +384,11 @@ libvirt_charPtrUnwrap(PyObject *obj,
 #else
     ret = PyString_AsString(obj);
 #endif
-    if (ret)
+    if (ret) {
         *str = strdup(ret);
+        if (!*str)
+            PyErr_NoMemory();
+    }
 #if PY_MAJOR_VERSION > 2
     Py_DECREF(bytes);
 #endif
-- 
2.17.1




More information about the libvir-list mailing list