Skip to content

Commit d492766

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #78538: shmop memory leak
2 parents 7b4a4d2 + 4c6ad09 commit d492766

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

TSRM/tsrm_win32.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ TSRM_API void *shmat(int key, const void *shmaddr, int flags)
718718
TSRM_API int shmdt(const void *shmaddr)
719719
{/*{{{*/
720720
shm_pair *shm = shm_get(0, (void*)shmaddr);
721+
int ret;
721722

722723
if (!shm->segment) {
723724
return -1;
@@ -727,7 +728,12 @@ TSRM_API int shmdt(const void *shmaddr)
727728
shm->descriptor->shm_lpid = getpid();
728729
shm->descriptor->shm_nattch--;
729730

730-
return UnmapViewOfFile(shm->addr) ? 0 : -1;
731+
ret = UnmapViewOfFile(shm->addr) ? 0 : -1;
732+
if (!ret && shm->descriptor->shm_nattch <= 0) {
733+
ret = UnmapViewOfFile(shm->descriptor) ? 0 : -1;
734+
shm->descriptor = NULL;
735+
}
736+
return ret;
731737
}/*}}}*/
732738

733739
TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf)

0 commit comments

Comments
 (0)