|
|
d0ea73 |
From da45c7c305a8ed03b7b1b11f6524e1321c5ad2b3 Mon Sep 17 00:00:00 2001
|
|
|
d0ea73 |
From: Pino Toscano <ptoscano@redhat.com>
|
|
|
d0ea73 |
Date: Tue, 22 Jan 2019 12:43:11 +0100
|
|
|
d0ea73 |
Subject: [PATCH] python: fix call of Python handlers of events
|
|
|
d0ea73 |
|
|
|
d0ea73 |
Make sure to reference the arguments, to make sure they are kept alive
|
|
|
d0ea73 |
during the function call; this is visible when setting an event handler
|
|
|
d0ea73 |
for the CLOSE event, and testing it with Python 3.
|
|
|
d0ea73 |
|
|
|
d0ea73 |
This does not seem to create a memory leak e.g. with Python 2.
|
|
|
d0ea73 |
|
|
|
d0ea73 |
Also, switch away from the quasi-internal PyEval_CallObject to the
|
|
|
d0ea73 |
public PyObject_CallObject, which takes care of doing safety checks.
|
|
|
d0ea73 |
|
|
|
d0ea73 |
(cherry picked from commit 85235aec837716f1ddb2926b9a59a02543195500)
|
|
|
d0ea73 |
---
|
|
|
d0ea73 |
python/handle.c | 3 ++-
|
|
|
d0ea73 |
1 file changed, 2 insertions(+), 1 deletion(-)
|
|
|
d0ea73 |
|
|
|
d0ea73 |
diff --git a/python/handle.c b/python/handle.c
|
|
|
d0ea73 |
index 1ffa4588a..13a93ad8c 100644
|
|
|
d0ea73 |
--- a/python/handle.c
|
|
|
d0ea73 |
+++ b/python/handle.c
|
|
|
d0ea73 |
@@ -136,11 +136,12 @@ guestfs_int_py_event_callback_wrapper (guestfs_h *g,
|
|
|
d0ea73 |
args = Py_BuildValue ("(Kis#O)",
|
|
|
d0ea73 |
(unsigned PY_LONG_LONG) event, event_handle,
|
|
|
d0ea73 |
buf, buf_len, py_array);
|
|
|
d0ea73 |
+ Py_INCREF (args);
|
|
|
d0ea73 |
|
|
|
d0ea73 |
if (PyEval_ThreadsInitialized ())
|
|
|
d0ea73 |
py_save = PyGILState_Ensure ();
|
|
|
d0ea73 |
|
|
|
d0ea73 |
- py_r = PyEval_CallObject (py_callback, args);
|
|
|
d0ea73 |
+ py_r = PyObject_CallObject (py_callback, args);
|
|
|
d0ea73 |
|
|
|
d0ea73 |
if (PyEval_ThreadsInitialized ())
|
|
|
d0ea73 |
PyGILState_Release (py_save);
|
|
|
d0ea73 |
--
|
|
|
d0ea73 |
2.20.1
|
|
|
d0ea73 |
|