Richard W.M. Jones
2023-Feb-17 17:45 UTC
[Libguestfs] [PATCH v3 0/2] python: Avoid leaking py_array and py_args in event callbacks
Version 1 was here: https://listman.redhat.com/archives/libguestfs/2023-February/030732.html (Ignore version 2 which had a mistake, this is version 3) Following Eric's suggestion here: https://listman.redhat.com/archives/libguestfs/2023-February/030746.html let's decrement the reference of py_array right after adding it to the args. (This works even if args fails to be built). However the other part of Eric's suggestion is wrong as it ends up calling Py_DECREF (args) when args == NULL along the error path. This lead me to look more closely at this patch: https://listman.redhat.com/archives/libguestfs/2019-January/020346.html which I believe is wrong (at least, the part that fiddles with the reference to args). I cannot reproduce the original problem, nor can I find any justification by looking at the documentation of PyObject_CallObject. So we start by reverting that commit. This means we are only decrementing args once, and not allow the error path. I tested this with: - with the reproducer - with the reproducer and bbf396fc5 reverted - normal Python test suite Rich.
Richard W.M. Jones
2023-Feb-17 17:45 UTC
[Libguestfs] [PATCH v3 1/2] Revert "python: fix call of Python handlers of events"
This reverts commit 85235aec837716f1ddb2926b9a59a02543195500. --- python/handle.c | 1 - 1 file changed, 1 deletion(-) diff --git a/python/handle.c b/python/handle.c index bf639b5789..8eeabe60a7 100644 --- a/python/handle.c +++ b/python/handle.c @@ -139,7 +139,6 @@ guestfs_int_py_event_callback_wrapper (guestfs_h *g, goto out; } - Py_INCREF (args); py_r = PyObject_CallObject (py_callback, args); Py_DECREF (args); if (py_r != NULL) -- 2.39.0
Richard W.M. Jones
2023-Feb-17 17:45 UTC
[Libguestfs] [PATCH v3 2/2] python: Avoid leaking py_array and py_args in event callbacks
See also: https://listman.redhat.com/archives/libguestfs/2023-February/030730.html https://listman.redhat.com/archives/libguestfs/2023-February/030745.html https://listman.redhat.com/archives/libguestfs/2023-February/030746.html Fixes: commit 6ef5837e2d8c5d4d83eff51c0201eb2e08f719de Thanks: Laszlo Ersek, Eric Blake --- python/handle.c | 1 + 1 file changed, 1 insertion(+) diff --git a/python/handle.c b/python/handle.c index 8eeabe60a7..85089e6bce 100644 --- a/python/handle.c +++ b/python/handle.c @@ -134,6 +134,7 @@ guestfs_int_py_event_callback_wrapper (guestfs_h *g, args = Py_BuildValue ("(Kiy#O)", (unsigned PY_LONG_LONG) event, event_handle, buf, buf_len, py_array); + Py_DECREF (py_array); if (args == NULL) { PyErr_PrintEx (0); goto out; -- 2.39.0
Maybe Matching Threads
- python: Avoid leaking py_array and py_args in event callbacks
- [PATCH] python: Avoid leaking py_array along error paths
- [PATCH 1/2] python: Avoid crash if callback parameters cannot be built
- [PATCH] python: Avoid leaking py_array along error paths
- [PATCH v2 0/2] python: fixes for Python 3