From dee0e24be33c95028b83fb5095426e8a287e5ae1 Mon Sep 17 00:00:00 2001 From: Gilchrist Dadaglo Date: Tue, 8 Dec 2020 14:37:14 +0000 Subject: [PATCH] BUG/MEDIUM: spoa/python: Fixing references to None As per https://docs.python.org/3/c-api/none.html, None has to be treated exactly like other objects for reference counting. So, when we use it, we need to INCREF and when we are done, DECREF This patch must be backported as far as 2.0. (cherry picked from commit bdd034947c4a3a6f8c41af9bf6e62b7a74b4ebbc) Signed-off-by: Christopher Faulet (cherry picked from commit 30189a6e056799f38d57478b04baded0868a431b) Signed-off-by: Christopher Faulet (cherry picked from commit 752e24a9e42cd9fe76f6b0d070562dc180c92555) Signed-off-by: Christopher Faulet --- contrib/spoa_server/ps_python.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/spoa_server/ps_python.c b/contrib/spoa_server/ps_python.c index fa24921..7eadef6 100644 --- a/contrib/spoa_server/ps_python.c +++ b/contrib/spoa_server/ps_python.c @@ -525,6 +525,7 @@ static int ps_python_exec_message(struct worker *w, void *ref, int nargs, struct switch (args[i].value.type) { case SPOE_DATA_T_NULL: + Py_INCREF(Py_None); value = Py_None; break; case SPOE_DATA_T_BOOL: @@ -613,6 +614,7 @@ static int ps_python_exec_message(struct worker *w, void *ref, int nargs, struct value = PyString_FromStringAndSize(args[i].value.u.buffer.str, args[i].value.u.buffer.len); break; default: + Py_INCREF(Py_None); value = Py_None; break; } @@ -677,9 +679,7 @@ static int ps_python_exec_message(struct worker *w, void *ref, int nargs, struct PyErr_Print(); return 0; } - if (result != Py_None) { - Py_DECREF(result); - } + Py_DECREF(result); return 1; } -- 1.7.10.4