From: Sascha Schumann Date: Fri, 18 May 2001 23:38:46 +0000 (+0000) Subject: munmap() file in RSHUTDOWN, if PHPWRITE fails. X-Git-Tag: PRE_GRANULAR_GARBAGE_FIX~355 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d5cfb03ac9126a2f0ff29bee873c36830fc037fe;p=php munmap() file in RSHUTDOWN, if PHPWRITE fails. --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 355e4cff8f..5f1fec4ece 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -48,6 +48,9 @@ #if HAVE_LOCALE_H #include #endif +#if HAVE_SYS_MMAN_H +#include +#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; } diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 86e7756c74..8a3c1e3de6 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -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 diff --git a/ext/standard/file.c b/ext/standard/file.c index a1d7a74e41..a395ab29ce 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -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 #include @@ -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;