Skip to content

Commit 1817230

Browse files
committed
Fix #78538: shmop memory leak
If the descriptor's refcount drops to zero, we have to unmap the respective file view, to avoid leaking memory.
1 parent b48f262 commit 1817230

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ PHP NEWS
3939
. Fixed bug #78982 (pdo_pgsql returns dead persistent connection). (SATŌ
4040
Kentarō)
4141

42+
- Shmop:
43+
. Fixed bug #78538 (shmop memory leak). (cmb)
44+
4245
18 Dec 2019, PHP 7.3.13
4346

4447
- Bcmath:

TSRM/tsrm_win32.c

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

725726
if (!shm->segment) {
726727
return -1;
@@ -730,7 +731,12 @@ TSRM_API int shmdt(const void *shmaddr)
730731
shm->descriptor->shm_lpid = getpid();
731732
shm->descriptor->shm_nattch--;
732733

733-
return UnmapViewOfFile(shm->addr) ? 0 : -1;
734+
ret = UnmapViewOfFile(shm->addr) ? 0 : -1;
735+
if (!ret && shm->descriptor->shm_nattch <= 0) {
736+
ret = UnmapViewOfFile(shm->descriptor) ? 0 : -1;
737+
shm->descriptor = NULL;
738+
}
739+
return ret;
734740
}/*}}}*/
735741

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

0 commit comments

Comments
 (0)