]> granicus.if.org Git - php/commitdiff
fix memleak in php 5.2, simplify code slightly
authorGreg Beaver <cellog@php.net>
Sat, 22 Mar 2008 21:54:55 +0000 (21:54 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 22 Mar 2008 21:54:55 +0000 (21:54 +0000)
ext/phar/phar.c
ext/phar/util.c

index a34c642f3a6692bdd05faa658c820f473aaf9ffc..6365c2ded788e30e8f2c7b1a81d75322a0874d1f 100644 (file)
@@ -2555,21 +2555,13 @@ static long stream_fteller_for_zend(void *handle TSRMLS_DC) /* {{{ */
 zend_op_array *(*phar_orig_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC);
 #if PHP_VERSION_ID >= 50300
 #define phar_orig_zend_open zend_stream_open_function
-#else
-int (*phar_orig_zend_open)(const char *filename, zend_file_handle *handle TSRMLS_DC);
-#endif
-
-/*
- Used to add the fake CWD to include_path prior to parsing it in PHP 5.3+
- Does complete include_path scan for file in PHP 5.2
-
- This is only called in PHP 5.2 if we know for certain that we are running within
- a phar, and only supports phar stream wrapper in 5.2.
- */
 char *phar_resolve_path(const char *filename, int filename_len TSRMLS_DC)
 {
        return phar_find_in_include_path((char *) filename, filename_len, NULL TSRMLS_CC);
 }
+#else
+int (*phar_orig_zend_open)(const char *filename, zend_file_handle *handle TSRMLS_DC);
+#endif
 
 static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC) /* {{{ */
 {
@@ -2669,6 +2661,9 @@ int phar_zend_open(const char *filename, zend_file_handle *handle TSRMLS_DC) /*
                        if (!handle->opened_path) {
                                handle->opened_path = entry;
                        }
+                       if (entry != filename) {
+                               handle->free_filename = 1;
+                       }
                        return SUCCESS;
                }
                if (entry != filename) {
index b7841806df0b04af9e379488988d2c765f228cfc..d11d020f9a9c4f7531c21ec7b6e0bc84eca9b58e 100644 (file)
@@ -361,10 +361,7 @@ doit:
                }
        }
        /* test for stream wrappers and return */
-       for (p = filename; p - filename < filename_len && (isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'); p++) {
-               n++;
-       }
-
+       for (p = filename; p - filename < filename_len && (isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'); p++, n++);
        if (n < filename_len - 3 && (*p == ':') && (!strncmp("//", p+1, 2) || ( filename_len > 4 && !memcmp("data", filename, 4)))) {
                /* found stream wrapper, this is an absolute path until stream wrappers implement realpath */
                return estrndup(filename, filename_len);
@@ -381,9 +378,7 @@ doit:
                        maybe_stream = 0;
                        goto not_stream;
                }
-               for (p = ptr, n = 0; p < end && (isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'); p++) {
-                       n++;
-               }
+               for (p = ptr, n = 0; p < end && (isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'); p++, n++);
 
                if (n == end - ptr && *p && !strncmp("//", p+1, 2)) {
                        is_stream_wrapper = 1;
@@ -480,9 +475,7 @@ not_stream:
                        memcpy(trypath+exec_fname_length + 1, filename, filename_len+1);
 
                        /* search for stream wrapper */
-                       for (p = trypath; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++) {
-                               n++;
-                       }
+                       for (p = trypath; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++, n++);
                        if (n < exec_fname_length - 3 && (*p == ':') && (n > 1) && (!strncmp("//", p+1, 2) || !memcmp("data", trypath, 4))) {
                                char *actual;