From d9f590075d0fc2c4336a6c7268206f095030415f Mon Sep 17 00:00:00 2001 From: Thomas Sader Date: Sat, 20 Jul 2024 11:58:52 +0200 Subject: [PATCH] Fix python reference counting for binds Fixes segfaults --- src/mod/python.mod/pycmds.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mod/python.mod/pycmds.c b/src/mod/python.mod/pycmds.c index 9f6754adb..d1ae78e5c 100644 --- a/src/mod/python.mod/pycmds.c +++ b/src/mod/python.mod/pycmds.c @@ -260,7 +260,7 @@ static PyObject *py_bind(PyObject *self, PyObject *args) { PyErr_SetString(EggdropError, "callback is not callable"); return NULL; } - Py_IncRef(callback); + Py_INCREF(callback); bind = PyObject_New(PythonBind, &PythonBindType); bind->mask = strdup(mask); @@ -273,6 +273,7 @@ static PyObject *py_bind(PyObject *self, PyObject *args) { Tcl_CreateObjCommand(tclinterp, bind->tclcmdname, tcl_call_python, bind, python_bind_destroyed); bind_bind_entry(tl, flags, mask, bind->tclcmdname); + Py_INCREF((PyObject *)bind); return (PyObject *)bind; }