From: Greg Beaver Date: Sat, 22 Mar 2008 21:54:55 +0000 (+0000) Subject: fix memleak in php 5.2, simplify code slightly X-Git-Tag: RELEASE_2_0_0a1~38 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=01e5bbbaf5ecedc9910d193738449db8020adfc8;p=php fix memleak in php 5.2, simplify code slightly --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index a34c642f3a..6365c2ded7 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -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) { diff --git a/ext/phar/util.c b/ext/phar/util.c index b7841806df..d11d020f9a 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -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;