]> granicus.if.org Git - php/commitdiff
munmap() file in RSHUTDOWN, if PHPWRITE fails.
authorSascha Schumann <sas@php.net>
Fri, 18 May 2001 23:38:46 +0000 (23:38 +0000)
committerSascha Schumann <sas@php.net>
Fri, 18 May 2001 23:38:46 +0000 (23:38 +0000)
ext/standard/basic_functions.c
ext/standard/basic_functions.h
ext/standard/file.c

index 355e4cff8f602c5ca37537ab41f577fe0c5fbf49..5f1fec4ece1482d282b7d2a45259cfd0ec128c4f 100644 (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;
 }
 
index 86e7756c7445151c02a2d547c1a2ef1d29b5ce88..8a3c1e3de6ccd09a7cd184ec923799ade579b178 100644 (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
index a1d7a74e4169a6828422054b797bb9f50a403729..a395ab29ceb6b1735187f68d8f35fbea6348687d 100644 (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;