]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Revert "We never manually incref on the module"
authorNick Porter <nick@portercomputing.co.uk>
Sat, 12 Apr 2025 18:10:51 +0000 (19:10 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Sat, 12 Apr 2025 18:27:07 +0000 (19:27 +0100)
This reverts commit 798de18ec34c1ea49f2d5d6041f779c4760d41bd.

Actually we do need to do this

src/modules/rlm_python/rlm_python.c

index f01b5cc0c2200ab22a613874e49fe97bc759886b..1f6c0cb09ff4b01799c53f264128c96c701867fb 100644 (file)
@@ -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;
 }