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

Pavel Hrdina posted 4 patches 6 years, 11 months ago
[libvirt] [python PATCH 2/4] typewrappers: Fix libvirt_charPtrUnwrap to set an exception if it fails
Posted by Pavel Hrdina 6 years, 11 months ago
If the function fails it should always set an exception.

Signed-off-by: Pavel Hrdina <phrdina@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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [python PATCH 2/4] typewrappers: Fix libvirt_charPtrUnwrap to set an exception if it fails
Posted by Ján Tomko 6 years, 11 months ago
On Tue, Jun 12, 2018 at 07:16:39AM +0200, Pavel Hrdina wrote:
>If the function fails it should always set an exception.
>
>Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
>---
> typewrappers.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list