Skip to content

Commit f7cb537

Browse files
committed
Fix Windows shared memory segment cleanup in shmctl IPC_RMID
Add proper handle cleanup when marking shared memory segment for deletion. Previously, shmctl(IPC_RMID) only marked the segment by setting key to -1 but did not close the Windows file mapping handle, causing the segment to persist in the system. This led to errors when trying to reopen segments with the same key: - Segment remained accessible via OpenFileMapping() - But had key = -1, failing validation checks - Resulted in "Invalid argument" errors Now properly closes the handle, allowing Windows to destroy the named mapping object when no processes are attached, matching POSIX semantics where IPC_RMID marks segment for deletion. Fixes issue where shmop_open() with 'c' flag fails after shmop_delete().
1 parent 04f3226 commit f7cb537

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

TSRM/tsrm_win32.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,11 @@ TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf)
823823
case IPC_RMID:
824824
if (shm->descriptor->shm_nattch < 1) {
825825
shm->descriptor->shm_perm.key = -1;
826+
/* Close handle to allow Windows to destroy the named mapping object */
827+
if (shm->segment && shm->segment != INVALID_HANDLE_VALUE) {
828+
CloseHandle(shm->segment);
829+
shm->segment = INVALID_HANDLE_VALUE;
830+
}
826831
}
827832
return 0;
828833

0 commit comments

Comments
 (0)