mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
[3.11] bpo-40882: Fix a memory leak in SharedMemory on Windows (GH-20684) (#99973)
bpo-40882: Fix a memory leak in SharedMemory on Windows (GH-20684)
In multiprocessing.shared_memory.SharedMemory(), the temporary view
returned by MapViewOfFile() should be unmapped when it is no longer
needed.
(cherry picked from commit 85c128e34d
)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
This commit is contained in:
parent
7f2bcc7aaa
commit
374b0a2ace
4 changed files with 58 additions and 2 deletions
|
@ -1402,6 +1402,30 @@ _winapi_MapViewOfFile_impl(PyObject *module, HANDLE file_map,
|
|||
return address;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_winapi.UnmapViewOfFile
|
||||
|
||||
address: LPCVOID
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_winapi_UnmapViewOfFile_impl(PyObject *module, LPCVOID address)
|
||||
/*[clinic end generated code: output=4f7e18ac75d19744 input=8c4b6119ad9288a3]*/
|
||||
{
|
||||
BOOL success;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
success = UnmapViewOfFile(address);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
if (!success) {
|
||||
return PyErr_SetFromWindowsErr(0);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_winapi.OpenFileMapping -> HANDLE
|
||||
|
||||
|
@ -2095,6 +2119,7 @@ static PyMethodDef winapi_functions[] = {
|
|||
_WINAPI_READFILE_METHODDEF
|
||||
_WINAPI_SETNAMEDPIPEHANDLESTATE_METHODDEF
|
||||
_WINAPI_TERMINATEPROCESS_METHODDEF
|
||||
_WINAPI_UNMAPVIEWOFFILE_METHODDEF
|
||||
_WINAPI_VIRTUALQUERYSIZE_METHODDEF
|
||||
_WINAPI_WAITNAMEDPIPE_METHODDEF
|
||||
_WINAPI_WAITFORMULTIPLEOBJECTS_METHODDEF
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue