diff --git a/CHANGES.txt b/CHANGES.txt index f14663b682..7527579995 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -32,6 +32,7 @@ Coming in build 309, as yet unreleased * Improved handling of dict iterations and fallbacks (removes Python 2 support code, small general speed improvement) (#2332, #2330, @Avasam) * Fixed "Open GL Demo" (`Pythonwin/pywin/Demos/openGLDemo.py`) and restore "Font" demo in `Pythonwin/pywin/Demos/guidemo.py` (#2345, @Avasam) * Fixed accidentally trying to raise an undefined name instead of an `Exception` in `Pythonwin/pywin/debugger/debugger.py` (#2326, @Avasam) +* Fixed PythonService DoLogMessage raising fatal GIL lock error (#2426, JacobNolan1) Build 308, released 2024-10-12 ------------------------------ diff --git a/win32/src/PythonService.cpp b/win32/src/PythonService.cpp index c6d8e13649..5b6485e33d 100644 --- a/win32/src/PythonService.cpp +++ b/win32/src/PythonService.cpp @@ -173,9 +173,11 @@ static PyObject *DoLogMessage(WORD errorType, PyObject *obMsg) DWORD errorCode = errorType == EVENTLOG_ERROR_TYPE ? PYS_E_GENERIC_ERROR : PYS_E_GENERIC_WARNING; LPCTSTR inserts[] = {msg, NULL}; BOOL ok; - Py_BEGIN_ALLOW_THREADS ok = ReportError(errorCode, inserts, errorType); - PyWinObject_FreeWCHAR(msg); - Py_END_ALLOW_THREADS if (!ok) return PyWin_SetAPIError("RegisterEventSource/ReportEvent"); + Py_BEGIN_ALLOW_THREADS + ok = ReportError(errorCode, inserts, errorType); + Py_END_ALLOW_THREADS + PyWinObject_FreeWCHAR(msg); // free msg before potentially raising error + if (!ok) return PyWin_SetAPIError("RegisterEventSource/ReportEvent"); Py_INCREF(Py_None); return Py_None; }