[python PATCHv2 1/2] event: fix domain reference bugs

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

 



Noticed this bug while adding qemu monitor events; there's probably
lots of other misuse of libvirt_virDomainPtrWrap, but for now I'm
limiting the fix to all copied-and-pasted event callbacks, since
I'm about to copy it again in the next patch.  While at it, check
for failure to extract the "conn" key from the opaque callback
struct, and hoist that check to occur before we reach the point
where it is harder to undo on failure (the network code was the
only code that had it in the right place, but then it failed to
restore thread state on failure).

The graphics callback is still not clean; but incremental
improvements are better than nothing.

* libvirt-override.c (libvirt_virConnectDomainEventCallback)
(libvirt_virConnectDomainEvetnLifecycleCallback)
(libvirt_virConnectDomainEventGenericCallback)
(libvirt_virConnectDomainEventRTCChangeCallback)
(libvirt_virConnectDomainEventWatchdogCallback)
(libvirt_virConnectDomainEventIOErrorCallback)
(libvirt_virConnectDomainEventIOErrorReasonCallback)
(libvirt_virConnectDomainEventGraphicsCallback)
(libvirt_virConnectDomainEventBlockJobCallback)
(libvirt_virConnectDomainEventDiskChangeCallback)
(libvirt_virConnectDomainEventTrayChangeCallback)
(libvirt_virConnectDomainEventPMWakeupCallback)
(libvirt_virConnectDomainEventPMSuspendCallback)
(libvirt_virConnectDomainEventBalloonChangeCallback)
(libvirt_virConnectDomainEventPMSuspendDiskCallback)
(libvirt_virConnectDomainEventDeviceRemovedCallback): Don't pass
NULL to PyObject_CallMethod.
(libvirt_virConnectNetworkEventLifecycleCallback): Likewise, and
don't corrupt thread state.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 libvirt-override.c | 319 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 200 insertions(+), 119 deletions(-)

diff --git a/libvirt-override.c b/libvirt-override.c
index 6a85d24..9dc6ad4 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -5020,7 +5020,7 @@ libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
                                       int detail,
                                       void *opaque)
 {
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;

     PyObject *pyobj_conn = (PyObject*)opaque;
     PyObject *pyobj_dom;
@@ -5031,7 +5031,10 @@ libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,

     /* Create a python instance of this virDomainPtr */
     virDomainRef(dom);
-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }

     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
@@ -5042,6 +5045,7 @@ libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,

     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -5055,8 +5059,8 @@ libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
 }

 static PyObject *
-libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject * self,
-                                      PyObject * args)
+libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject *self,
+                                      PyObject *args)
 {
     PyObject *py_retval;        /* return value */
     PyObject *pyobj_conn;       /* virConnectPtr */
@@ -5074,7 +5078,7 @@ libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject * self,

     DEBUG("libvirt_virConnectDomainEventRegister(%p %p) called\n",
           pyobj_conn, pyobj_conn_inst);
-    conn   = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);

     Py_INCREF(pyobj_conn_inst);

@@ -5082,7 +5086,7 @@ libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject * self,

     ret = virConnectDomainEventRegister(conn,
                                         libvirt_virConnectDomainEventCallback,
-                                        (void *)pyobj_conn_inst, NULL);
+                                        pyobj_conn_inst, NULL);

     LIBVIRT_END_ALLOW_THREADS;

@@ -5091,8 +5095,8 @@ libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject * self,
 }

 static PyObject *
-libvirt_virConnectDomainEventDeregister(ATTRIBUTE_UNUSED PyObject * self,
-                                        PyObject * args)
+libvirt_virConnectDomainEventDeregister(ATTRIBUTE_UNUSED PyObject *self,
+                                        PyObject *args)
 {
     PyObject *py_retval;
     PyObject *pyobj_conn;
@@ -5108,7 +5112,7 @@ libvirt_virConnectDomainEventDeregister(ATTRIBUTE_UNUSED PyObject * self,

     DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);

-    conn   = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);

     LIBVIRT_BEGIN_ALLOW_THREADS;

@@ -5659,22 +5663,26 @@ libvirt_virConnectDomainEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUS
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;

+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
+    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
+    Py_DECREF(dictKey);
+
     /* Create a python instance of this virDomainPtr */
     virDomainRef(dom);
-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
     Py_INCREF(pyobj_cbData);

-    dictKey = libvirt_constcharPtrWrap("conn");
-    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
-    Py_DECREF(dictKey);
-
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventLifecycleCallback",
@@ -5686,6 +5694,7 @@ libvirt_virConnectDomainEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUS
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -5705,22 +5714,26 @@ libvirt_virConnectDomainEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;

+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
+    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
+    Py_DECREF(dictKey);
+
     /* Create a python instance of this virDomainPtr */
     virDomainRef(dom);
-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
     Py_INCREF(pyobj_cbData);

-    dictKey = libvirt_constcharPtrWrap("conn");
-    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
-    Py_DECREF(dictKey);
-
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventGenericCallback",
@@ -5730,6 +5743,7 @@ libvirt_virConnectDomainEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -5750,22 +5764,26 @@ libvirt_virConnectDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUS
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;

+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
+    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
+    Py_DECREF(dictKey);
+
     /* Create a python instance of this virDomainPtr */
     virDomainRef(dom);
-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
     Py_INCREF(pyobj_cbData);

-    dictKey = libvirt_constcharPtrWrap("conn");
-    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
-    Py_DECREF(dictKey);
-
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventRTCChangeCallback",
@@ -5777,6 +5795,7 @@ libvirt_virConnectDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUS
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -5797,22 +5816,26 @@ libvirt_virConnectDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSE
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;

+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
+    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
+    Py_DECREF(dictKey);
+
     /* Create a python instance of this virDomainPtr */
     virDomainRef(dom);
-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
     Py_INCREF(pyobj_cbData);

-    dictKey = libvirt_constcharPtrWrap("conn");
-    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
-    Py_DECREF(dictKey);
-
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventWatchdogCallback",
@@ -5824,6 +5847,7 @@ libvirt_virConnectDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSE
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -5846,22 +5870,26 @@ libvirt_virConnectDomainEventIOErrorCallback(virConnectPtr conn ATTRIBUTE_UNUSED
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;

+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
+    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
+    Py_DECREF(dictKey);
+
     /* Create a python instance of this virDomainPtr */
     virDomainRef(dom);
-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
     Py_INCREF(pyobj_cbData);

-    dictKey = libvirt_constcharPtrWrap("conn");
-    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
-    Py_DECREF(dictKey);
-
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventIOErrorCallback",
@@ -5873,6 +5901,7 @@ libvirt_virConnectDomainEventIOErrorCallback(virConnectPtr conn ATTRIBUTE_UNUSED
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -5896,22 +5925,26 @@ libvirt_virConnectDomainEventIOErrorReasonCallback(virConnectPtr conn ATTRIBUTE_
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;

+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
+    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
+    Py_DECREF(dictKey);
+
     /* Create a python instance of this virDomainPtr */
     virDomainRef(dom);
-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
     Py_INCREF(pyobj_cbData);

-    dictKey = libvirt_constcharPtrWrap("conn");
-    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
-    Py_DECREF(dictKey);
-
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventIOErrorReasonCallback",
@@ -5923,6 +5956,7 @@ libvirt_virConnectDomainEventIOErrorReasonCallback(virConnectPtr conn ATTRIBUTE_
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -5947,7 +5981,7 @@ libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSE
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     PyObject *pyobj_local;
@@ -5958,15 +5992,20 @@ libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSE

     LIBVIRT_ENSURE_THREAD_STATE;

+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
+    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
+    Py_DECREF(dictKey);
+
     /* Create a python instance of this virDomainPtr */
     virDomainRef(dom);
-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
     Py_INCREF(pyobj_cbData);

-    dictKey = libvirt_constcharPtrWrap("conn");
-    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
-    Py_DECREF(dictKey);
-
+    /* FIXME This code should check for errors... */
     pyobj_local = PyDict_New();
     PyDict_SetItem(pyobj_local,
                    libvirt_constcharPtrWrap("family"),
@@ -6010,6 +6049,7 @@ libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSE
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -6032,22 +6072,26 @@ libvirt_virConnectDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSE
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;

+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
+    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
+    Py_DECREF(dictKey);
+
     /* Create a python instance of this virDomainPtr */
     virDomainRef(dom);
-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
     Py_INCREF(pyobj_cbData);

-    dictKey = libvirt_constcharPtrWrap("conn");
-    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
-    Py_DECREF(dictKey);
-
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventBlockPullCallback",
@@ -6057,10 +6101,9 @@ libvirt_virConnectDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSE
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
-#if DEBUG_ERROR
-        printf("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
-#endif
+        DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
     } else {
         Py_DECREF(pyobj_ret);
@@ -6082,22 +6125,26 @@ libvirt_virConnectDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNU
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;
-    /* Create a python instance of this virDomainPtr */
-    virDomainRef(dom);

-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
-    Py_INCREF(pyobj_cbData);
-
-    dictKey = libvirt_constcharPtrWrap("conn");
+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
     pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
     Py_DECREF(dictKey);

+    /* Create a python instance of this virDomainPtr */
+    virDomainRef(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
+    Py_INCREF(pyobj_cbData);
+
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventDiskChangeCallback",
@@ -6109,6 +6156,7 @@ libvirt_virConnectDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNU
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -6130,22 +6178,26 @@ libvirt_virConnectDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNU
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;
-    /* Create a python instance of this virDomainPtr */
-    virDomainRef(dom);

-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
-    Py_INCREF(pyobj_cbData);
-
-    dictKey = libvirt_constcharPtrWrap("conn");
+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
     pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
     Py_DECREF(dictKey);

+    /* Create a python instance of this virDomainPtr */
+    virDomainRef(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
+    Py_INCREF(pyobj_cbData);
+
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventTrayChangeCallback",
@@ -6156,6 +6208,7 @@ libvirt_virConnectDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNU
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -6176,22 +6229,26 @@ libvirt_virConnectDomainEventPMWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSE
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;
-    /* Create a python instance of this virDomainPtr */
-    virDomainRef(dom);

-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
-    Py_INCREF(pyobj_cbData);
-
-    dictKey = libvirt_constcharPtrWrap("conn");
+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
     pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
     Py_DECREF(dictKey);

+    /* Create a python instance of this virDomainPtr */
+    virDomainRef(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
+    Py_INCREF(pyobj_cbData);
+
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventPMWakeupCallback",
@@ -6203,6 +6260,7 @@ libvirt_virConnectDomainEventPMWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSE
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -6223,22 +6281,26 @@ libvirt_virConnectDomainEventPMSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUS
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;
-    /* Create a python instance of this virDomainPtr */
-    virDomainRef(dom);

-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
-    Py_INCREF(pyobj_cbData);
-
-    dictKey = libvirt_constcharPtrWrap("conn");
+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
     pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
     Py_DECREF(dictKey);

+    /* Create a python instance of this virDomainPtr */
+    virDomainRef(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
+    Py_INCREF(pyobj_cbData);
+
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventPMSuspendCallback",
@@ -6250,6 +6312,7 @@ libvirt_virConnectDomainEventPMSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUS
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -6272,22 +6335,26 @@ libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;

+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
+    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
+    Py_DECREF(dictKey);
+
     /* Create a python instance of this virDomainPtr */
     virDomainRef(dom);
-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
     Py_INCREF(pyobj_cbData);

-    dictKey = libvirt_constcharPtrWrap("conn");
-    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
-    Py_DECREF(dictKey);
-
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventBalloonChangeCallback",
@@ -6299,6 +6366,7 @@ libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -6321,22 +6389,26 @@ libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;
-    /* Create a python instance of this virDomainPtr */
-    virDomainRef(dom);

-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
-    Py_INCREF(pyobj_cbData);
-
-    dictKey = libvirt_constcharPtrWrap("conn");
+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
     pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
     Py_DECREF(dictKey);

+    /* Create a python instance of this virDomainPtr */
+    virDomainRef(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
+    Py_INCREF(pyobj_cbData);
+
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventPMSuspendDiskCallback",
@@ -6348,6 +6420,7 @@ libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -6370,22 +6443,26 @@ libvirt_virConnectDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_dom;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;
-    /* Create a python instance of this virDomainPtr */
-    virDomainRef(dom);

-    pyobj_dom = libvirt_virDomainPtrWrap(dom);
-    Py_INCREF(pyobj_cbData);
-
-    dictKey = libvirt_constcharPtrWrap("conn");
+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
     pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
     Py_DECREF(dictKey);

+    /* Create a python instance of this virDomainPtr */
+    virDomainRef(dom);
+    if (!(pyobj_dom = libvirt_virDomainPtrWrap(dom))) {
+        virDomainFree(dom);
+        goto cleanup;
+    }
+    Py_INCREF(pyobj_cbData);
+
     /* Call the Callback Dispatcher */
     pyobj_ret = PyObject_CallMethod(pyobj_conn,
                                     (char*)"_dispatchDomainEventDeviceRemovedCallback",
@@ -6395,6 +6472,7 @@ libvirt_virConnectDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_dom);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -6409,8 +6487,8 @@ libvirt_virConnectDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_
 #endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */

 static PyObject *
-libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self,
-                                         PyObject * args)
+libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject *self,
+                                         PyObject *args)
 {
     PyObject *py_retval;        /* return value */
     PyObject *pyobj_conn;       /* virConnectPtr */
@@ -6517,8 +6595,8 @@ libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self,
 }

 static PyObject *
-libvirt_virConnectDomainEventDeregisterAny(ATTRIBUTE_UNUSED PyObject * self,
-                                           PyObject * args)
+libvirt_virConnectDomainEventDeregisterAny(ATTRIBUTE_UNUSED PyObject *self,
+                                           PyObject *args)
 {
     PyObject *py_retval;
     PyObject *pyobj_conn;
@@ -6533,7 +6611,7 @@ libvirt_virConnectDomainEventDeregisterAny(ATTRIBUTE_UNUSED PyObject * self,

     DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);

-    conn   = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);

     LIBVIRT_BEGIN_ALLOW_THREADS;

@@ -6563,22 +6641,24 @@ libvirt_virConnectNetworkEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNU
 {
     PyObject *pyobj_cbData = (PyObject*)opaque;
     PyObject *pyobj_net;
-    PyObject *pyobj_ret;
+    PyObject *pyobj_ret = NULL;
     PyObject *pyobj_conn;
     PyObject *dictKey;
     int ret = -1;

     LIBVIRT_ENSURE_THREAD_STATE;

-    dictKey = libvirt_constcharPtrWrap("conn");
-    if (!dictKey)
-        return ret;
+    if (!(dictKey = libvirt_constcharPtrWrap("conn")))
+        goto cleanup;
     pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
     Py_DECREF(dictKey);

     /* Create a python instance of this virNetworkPtr */
     virNetworkRef(net);
-    pyobj_net = libvirt_virNetworkPtrWrap(net);
+    if (!(pyobj_net = libvirt_virNetworkPtrWrap(net))) {
+        virNetworkFree(net);
+        goto cleanup;
+    }
     Py_INCREF(pyobj_cbData);

     /* Call the Callback Dispatcher */
@@ -6593,6 +6673,7 @@ libvirt_virConnectNetworkEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNU
     Py_DECREF(pyobj_cbData);
     Py_DECREF(pyobj_net);

+ cleanup:
     if (!pyobj_ret) {
         DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
         PyErr_Print();
@@ -6680,7 +6761,7 @@ static PyObject

     DEBUG("libvirt_virConnectNetworkEventDeregister(%p) called\n", pyobj_conn);

-    conn   = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);

     LIBVIRT_BEGIN_ALLOW_THREADS;

-- 
1.8.5.3

--
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]