munmap() file in RSHUTDOWN, if PHPWRITE fails.

This commit is contained in:
Sascha Schumann 2001-05-18 23:38:46 +00:00
parent d1697ad012
commit d5cfb03ac9
3 changed files with 22 additions and 0 deletions

View File

@ -48,6 +48,9 @@
#if HAVE_LOCALE_H
#include <locale.h>
#endif
#if HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#include "safe_mode.h"
#ifdef PHP_WIN32
#include "win32/unistd.h"
@ -830,6 +833,9 @@ PHP_RINIT_FUNCTION(basic)
BG(user_compare_func_name) = NULL;
BG(array_walk_func_name) = NULL;
BG(incomplete_class) = NULL;
#ifdef HAVE_MMAP
BG(mmap_file) = NULL;
#endif
BG(page_uid) = -1;
BG(page_inode) = -1;
BG(page_mtime) = -1;
@ -897,6 +903,12 @@ PHP_RSHUTDOWN_FUNCTION(basic)
BG(user_tick_functions) = NULL;
}
#ifdef HAVE_MMAP
if (BG(mmap_file)) {
munmap(BG(mmap_file), BG(mmap_len));
}
#endif
return SUCCESS;
}

View File

@ -188,6 +188,11 @@ typedef struct {
/* url_scanner_ex.re */
url_adapt_state_ex_t url_adapt_state_ex;
#endif
#ifdef HAVE_MMAP
void *mmap_file;
size_t mmap_len;
#endif
} php_basic_globals;
#ifdef ZTS

View File

@ -33,6 +33,7 @@
#include "ext/standard/exec.h"
#include "ext/standard/php_filestat.h"
#include "php_open_temporary_file.h"
#include "ext/standard/basic_functions.h"
#include <stdio.h>
#include <stdlib.h>
@ -1548,7 +1549,11 @@ static size_t php_passthru_fd(int socketd, FILE *fp, int issock)
len = sbuf.st_size - off;
p = mmap(0, len, PROT_READ, MAP_SHARED, fd, off);
if (p != (void *) MAP_FAILED) {
BLS_FETCH();
BG(mmap_file) = p;
BG(mmap_len) = len;
PHPWRITE(p, len);
BG(mmap_file) = NULL;
munmap(p, len);
bcount += len;
ready = 1;