diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2019-11-25 14:05:15 +0100 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2020-01-03 18:10:29 +0100 |
commit | 18172303f41b9891ae4b78b0c6f70d0d47ed539f (patch) | |
tree | f62e51461026ba57417d8248442334fdbb92e8bb /TSRM | |
parent | b48f2625b57f70eea858033e623e6bf13b595e3b (diff) | |
download | php-git-18172303f41b9891ae4b78b0c6f70d0d47ed539f.tar.gz |
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.
Diffstat (limited to 'TSRM')
-rw-r--r-- | TSRM/tsrm_win32.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c index 06ca965d64..cb2520e294 100644 --- a/TSRM/tsrm_win32.c +++ b/TSRM/tsrm_win32.c @@ -721,6 +721,7 @@ TSRM_API void *shmat(int key, const void *shmaddr, int flags) TSRM_API int shmdt(const void *shmaddr) {/*{{{*/ shm_pair *shm = shm_get(0, (void*)shmaddr); + int ret; if (!shm->segment) { return -1; @@ -730,7 +731,12 @@ TSRM_API int shmdt(const void *shmaddr) shm->descriptor->shm_lpid = getpid(); shm->descriptor->shm_nattch--; - return UnmapViewOfFile(shm->addr) ? 0 : -1; + ret = UnmapViewOfFile(shm->addr) ? 0 : -1; + if (!ret && shm->descriptor->shm_nattch <= 0) { + ret = UnmapViewOfFile(shm->descriptor) ? 0 : -1; + shm->descriptor = NULL; + } + return ret; }/*}}}*/ TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf) |