From: Gilchrist Dadaglo Date: Mon, 24 Aug 2020 19:21:31 +0000 (+0000) Subject: BUG/MAJOR: contrib/spoa-server: Fix unhandled python call leading to memory leak X-Git-Tag: v2.3-dev4~41 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=222f060be379126fa0890f6cd2820c4bd8d5ac90;p=haproxy-2.5.git BUG/MAJOR: contrib/spoa-server: Fix unhandled python call leading to memory leak The result from spoa evaluation of the user provided python code is never passed back to the main spoa process nor freed. Same for the keyword list passed. This results into the elements never freed by Python as reference count never goes down. https://docs.python.org/3/extending/extending.html#reference-counting-in-python This patch must be backported as far as 2.0. --- diff --git a/contrib/spoa_server/ps_python.c b/contrib/spoa_server/ps_python.c index be6fc4b..3ad64a7 100644 --- a/contrib/spoa_server/ps_python.c +++ b/contrib/spoa_server/ps_python.c @@ -738,10 +738,14 @@ static int ps_python_exec_message(struct worker *w, void *ref, int nargs, struct } result = PyObject_Call(python_ref, empty_array, fkw); + Py_DECREF(fkw); if (result == NULL) { PyErr_Print(); return 0; } + if (result != Py_None) { + Py_DECREF(result); + } return 1; }