From: Nick Porter Date: Sat, 12 Apr 2025 18:10:51 +0000 (+0100) Subject: Revert "We never manually incref on the module" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2b8e78a88501e2ee4305ccf7a8474f8986d497d;p=thirdparty%2Ffreeradius-server.git Revert "We never manually incref on the module" This reverts commit 798de18ec34c1ea49f2d5d6041f779c4760d41bd. Actually we do need to do this --- diff --git a/src/modules/rlm_python/rlm_python.c b/src/modules/rlm_python/rlm_python.c index f01b5cc0c22..1f6c0cb09ff 100644 --- a/src/modules/rlm_python/rlm_python.c +++ b/src/modules/rlm_python/rlm_python.c @@ -934,8 +934,14 @@ static int python_interpreter_init(module_inst_ctx_t const *mctx) return 0; } -static void python_interpreter_free(PyThreadState *interp) +static void python_interpreter_free(rlm_python_t *inst, PyThreadState *interp) { + /* + * We incremented the reference count earlier + * during module initialisation. + */ + Py_XDECREF(inst->module); + PyEval_RestoreThread(interp); /* Switches thread state and locks GIL */ Py_EndInterpreter(interp); /* Destroys interpreter (GIL still locked) - sets thread state to NULL */ PyThreadState_Swap(global_interpreter); /* Get a none-null thread state */ @@ -988,7 +994,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) case RLM_MODULE_REJECT: error: fr_cond_assert(PyEval_SaveThread() == inst->interpreter); - python_interpreter_free(inst->interpreter); + python_interpreter_free(inst, inst->interpreter); return -1; default: @@ -1044,7 +1050,7 @@ static int mod_detach(module_detach_ctx_t const *mctx) /* * Free the module specific interpreter */ - python_interpreter_free(inst->interpreter); + python_interpreter_free(inst, inst->interpreter); return 0; }