Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 13be7db

Browse files
committed
Fix usage of PyMem_Malloc() in overlapped.c
Issue #26563: Replace PyMem_Malloc() with PyMem_RawFree() since PostToQueueCallback() calls PyMem_RawFree() (previously PyMem_Free()) in a new C thread which doesn't hold the GIL.
1 parent 2025d78 commit 13be7db

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Modules/overlapped.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ PostToQueueCallback(PVOID lpParameter, BOOL TimerOrWaitFired)
238238
PostQueuedCompletionStatus(p->CompletionPort, TimerOrWaitFired,
239239
0, p->Overlapped);
240240
/* ignore possible error! */
241-
PyMem_Free(p);
241+
PyMem_RawFree(p);
242242
}
243243

244244
PyDoc_STRVAR(
@@ -262,7 +262,10 @@ overlapped_RegisterWaitWithQueue(PyObject *self, PyObject *args)
262262
&Milliseconds))
263263
return NULL;
264264

265-
pdata = PyMem_Malloc(sizeof(struct PostCallbackData));
265+
/* Use PyMem_RawMalloc() rather than PyMem_Malloc(), since
266+
PostToQueueCallback() will call PyMem_Free() from a new C thread
267+
which doesn't hold the GIL. */
268+
pdata = PyMem_RawMalloc(sizeof(struct PostCallbackData));
266269
if (pdata == NULL)
267270
return SetFromWindowsErr(0);
268271

@@ -273,7 +276,7 @@ overlapped_RegisterWaitWithQueue(PyObject *self, PyObject *args)
273276
pdata, Milliseconds,
274277
WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE))
275278
{
276-
PyMem_Free(pdata);
279+
PyMem_RawFree(pdata);
277280
return SetFromWindowsErr(0);
278281
}
279282

0 commit comments

Comments
 (0)