From f303840a86234778e3e8f78e2248723e38b453b8 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 22 Sep 2024 15:28:40 +0200 Subject: [PATCH] Prevent closing of unrelated handles If our `shmget()` fails for certain reasons, the segment handle is closed. However, the handle might be reused by Windows, and as such we must not close it again when shutting down the TSRM. Closes GH-15984. --- NEWS | 3 +++ TSRM/tsrm_win32.c | 1 + 2 files changed, 4 insertions(+) diff --git a/NEWS b/NEWS index 12dbbc7d3ae..f8e6f5ee82f 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,9 @@ PHP NEWS . Fixed bugs GH-15908 and GH-15026 (leak / assertion failure in streams.c). (nielsdos) +- TSRM: + . Prevent closing of unrelated handles. (cmb) + - XML: . Fixed bug GH-15868 (Assertion failure in xml_parse_into_struct after exception). (nielsdos) diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c index 0af03b6ed89..5d48ea2678a 100644 --- a/TSRM/tsrm_win32.c +++ b/TSRM/tsrm_win32.c @@ -707,6 +707,7 @@ TSRM_API int shmget(key_t key, size_t size, int flags) if (NULL != shm->descriptor && (shm->descriptor->shm_perm.key != key || size > shm->descriptor->shm_segsz)) { if (NULL != shm->segment) { CloseHandle(shm->segment); + shm->segment = INVALID_HANDLE_VALUE; } UnmapViewOfFile(shm->descriptor); shm->descriptor = NULL;