Skip to content

Commit d618bd5

Browse files
JacobNolan1Jacob Nolan
andauthored
PythonService DoLogMessage raising fatal GIL lock error. (#2426)
Co-authored-by: Jacob Nolan <[email protected]>
1 parent 0023fd3 commit d618bd5

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Coming in build 309, as yet unreleased
3232
* Improved handling of dict iterations and fallbacks (removes Python 2 support code, small general speed improvement) (#2332, #2330, @Avasam)
3333
* Fixed "Open GL Demo" (`Pythonwin/pywin/Demos/openGLDemo.py`) and restore "Font" demo in `Pythonwin/pywin/Demos/guidemo.py` (#2345, @Avasam)
3434
* Fixed accidentally trying to raise an undefined name instead of an `Exception` in `Pythonwin/pywin/debugger/debugger.py` (#2326, @Avasam)
35+
* Fixed PythonService DoLogMessage raising fatal GIL lock error (#2426, JacobNolan1)
3536

3637
Build 308, released 2024-10-12
3738
------------------------------

win32/src/PythonService.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,11 @@ static PyObject *DoLogMessage(WORD errorType, PyObject *obMsg)
173173
DWORD errorCode = errorType == EVENTLOG_ERROR_TYPE ? PYS_E_GENERIC_ERROR : PYS_E_GENERIC_WARNING;
174174
LPCTSTR inserts[] = {msg, NULL};
175175
BOOL ok;
176-
Py_BEGIN_ALLOW_THREADS ok = ReportError(errorCode, inserts, errorType);
177-
PyWinObject_FreeWCHAR(msg);
178-
Py_END_ALLOW_THREADS if (!ok) return PyWin_SetAPIError("RegisterEventSource/ReportEvent");
176+
Py_BEGIN_ALLOW_THREADS
177+
ok = ReportError(errorCode, inserts, errorType);
178+
Py_END_ALLOW_THREADS
179+
PyWinObject_FreeWCHAR(msg); // free msg before potentially raising error
180+
if (!ok) return PyWin_SetAPIError("RegisterEventSource/ReportEvent");
179181
Py_INCREF(Py_None);
180182
return Py_None;
181183
}

0 commit comments

Comments
 (0)