python: Memory leak: Free roots array along handle close path.
[libguestfs.git] / python / guestfs-py-byhand.c
index af9686f..53c2e98 100644 (file)
@@ -76,6 +76,7 @@ py_guestfs_close (PyObject *self, PyObject *args)
 
   for (i = 0; i < len; ++i)
     Py_XDECREF (callbacks[i]);
+  free (callbacks);
 
   Py_INCREF (Py_None);
   return Py_None;
@@ -91,6 +92,7 @@ py_guestfs_event_callback_wrapper (guestfs_h *g,
                                    const char *buf, size_t buf_len,
                                    const uint64_t *array, size_t array_len)
 {
+  PyGILState_STATE py_save = PyGILState_UNLOCKED;
   PyObject *py_callback = callback;
   PyObject *py_array;
   PyObject *args;
@@ -109,7 +111,14 @@ py_guestfs_event_callback_wrapper (guestfs_h *g,
                         (unsigned PY_LONG_LONG) event, event_handle,
                         buf, buf_len, py_array);
 
+  if (PyEval_ThreadsInitialized ())
+    py_save = PyGILState_Ensure ();
+
   py_r = PyEval_CallObject (py_callback, args);
+
+  if (PyEval_ThreadsInitialized ())
+    PyGILState_Release (py_save);
+
   Py_DECREF (args);
 
   if (py_r != NULL)
@@ -160,7 +169,7 @@ py_guestfs_set_event_callback (PyObject *self, PyObject *args)
   snprintf (key, sizeof key, "_python_event_%d", eh);
   guestfs_set_private (g, key, py_callback);
 
-  py_eh = PyInt_FromLong ((long) eh);
+  py_eh = PyLong_FromLong ((long) eh);
   return py_eh;
 }