diff options
author | Zackery Spytz <zspytz@gmail.com> | 2022-11-25 17:39:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-25 17:39:48 (GMT) |
commit | 85c128e34daec7625b74746e127afa25888ccde1 (patch) | |
tree | 81f9e08d696f6e61ecab4863e5cf345b9ee56906 /Modules/_winapi.c | |
parent | 8749121b07f48994ea47f2e7ff75fb13c13953f6 (diff) | |
download | cpython-85c128e34daec7625b74746e127afa25888ccde1.zip cpython-85c128e34daec7625b74746e127afa25888ccde1.tar.gz cpython-85c128e34daec7625b74746e127afa25888ccde1.tar.bz2 |
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.
Diffstat (limited to 'Modules/_winapi.c')
-rw-r--r-- | Modules/_winapi.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Modules/_winapi.c b/Modules/_winapi.c index 7a9bedb..bb4514c 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -1394,6 +1394,30 @@ _winapi_MapViewOfFile_impl(PyObject *module, HANDLE file_map, } /*[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 desired_access: DWORD @@ -2062,6 +2086,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 |