From: Greg Beaver Date: Sat, 3 Feb 2007 04:04:18 +0000 (+0000) Subject: fix mem leak on error, fix cwd issue. go back to BadMethodCallException for Phar... X-Git-Tag: RELEASE_1_0_0RC1~34 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=93b387d3275d2764b66bafc75af3a52e5a576577;p=php fix mem leak on error, fix cwd issue. go back to BadMethodCallException for Phar->set*CompressedAllFiles(). ALL TESTS PASS, RELEASE IS IMMINENT --- diff --git a/ext/phar/TODO b/ext/phar/TODO index 878a2b4477..6bf549a6b3 100644 --- a/ext/phar/TODO +++ b/ext/phar/TODO @@ -27,8 +27,8 @@ Version 1.0.0 streams interface [Greg] X Phar archive metadata Phar::setMetaData($metadata) Phar::getMetaData() [Greg] X support rename() in stream wrapper [Greg] - * update docs to reflect changes in error handling - * fix 011.phpt, 029.phpt for uncaught exceptions causing bad cleanup + X update docs to reflect changes in error handling [Greg] + X fix 011.phpt, 029.phpt for uncaught exceptions causing bad cleanup [Marcus/Greg] Version 1.1.0 diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 1a8d590df2..989dbe2cae 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -90,7 +90,9 @@ static void phar_destroy_phar_data(phar_archive_data *data TSRMLS_DC) /* {{{ */ efree(data->alias); data->alias = NULL; } - efree(data->fname); + if (data->fname) { + efree(data->fname); + } if (data->signature) { efree(data->signature); } @@ -134,7 +136,7 @@ static void destroy_phar_data_only(void *pDest) /* {{{ */ phar_archive_data *phar_data = *(phar_archive_data **) pDest; TSRMLS_FETCH(); - if (--phar_data->refcount < 0) { + if (EG(exception) || --phar_data->refcount < 0) { phar_destroy_phar_data(phar_data TSRMLS_CC); } } @@ -482,7 +484,7 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char #define MAPPHAR_FAIL(msg) \ efree(savebuf);\ if (mydata) {\ - efree(mydata);\ + phar_destroy_phar_data(mydata TSRMLS_CC);\ }\ if (signature) {\ efree(signature);\ @@ -885,6 +887,7 @@ int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias, int PHAR_GET_32(buffer, entry.flags); if (*(php_uint32 *) buffer) { if (phar_parse_metadata(fp, &buffer, endbuffer, &entry.metadata TSRMLS_CC) == FAILURE) { + efree(entry.filename); MAPPHAR_FAIL("unable to read file metadata in .phar file \"%s\""); } } else { @@ -895,16 +898,28 @@ int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias, int switch (entry.flags & PHAR_ENT_COMPRESSION_MASK) { case PHAR_ENT_COMPRESSED_GZ: #if !HAVE_ZLIB + if (entry.metadata) { + zval_ptr_dtor(&entry.metadata); + } + efree(entry.filename); MAPPHAR_FAIL("zlib extension is required for gz compressed .phar file \"%s\""); #endif break; case PHAR_ENT_COMPRESSED_BZ2: #if !HAVE_BZ2 + if (entry.metadata) { + zval_ptr_dtor(&entry.metadata); + } + efree(entry.filename); MAPPHAR_FAIL("bz2 extension is required for bzip2 compressed .phar file \"%s\""); #endif break; default: if (entry.uncompressed_filesize != entry.compressed_filesize) { + if (entry.metadata) { + zval_ptr_dtor(&entry.metadata); + } + efree(entry.filename); MAPPHAR_FAIL("internal corruption of phar \"%s\" (compressed and uncompressed size does not match for uncompressed entry)"); } break; @@ -2944,7 +2959,7 @@ static php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, char *path /* we must have at the very least phar://alias.phar/ */ if (!resource->scheme || !resource->host || !resource->path) { if (resource->host && !resource->path) { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: no directory in \"%s\", must have at least phar://%s/ for root directory", path, resource->host); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: no directory in \"%s\", must have at least phar://%s/ for root directory (always use full path to a new phar)", path, resource->host); php_url_free(resource); return NULL; } diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 6935055e0a..644fd36f36 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -403,12 +403,12 @@ PHP_METHOD(Phar, compressAllFilesGZ) PHAR_ARCHIVE_OBJECT(); if (PHAR_G(readonly)) { - zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Phar is readonly, cannot change compression"); } #if HAVE_ZLIB if (!pharobj_cancompress(&phar_obj->arc.archive->manifest TSRMLS_CC)) { - zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress all files as Gzip, some are compressed as bzip2 and cannot be uncompressed"); } pharobj_set_compression(&phar_obj->arc.archive->manifest, PHAR_ENT_COMPRESSED_GZ TSRMLS_CC); @@ -416,11 +416,11 @@ PHP_METHOD(Phar, compressAllFilesGZ) phar_flush(phar_obj->arc.archive, 0, 0, &error TSRMLS_CC); if (error) { - zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, error); + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, error); efree(error); } #else - zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress with Gzip compression, zlib extension is not enabled"); #endif } @@ -437,12 +437,12 @@ PHP_METHOD(Phar, compressAllFilesBZIP2) PHAR_ARCHIVE_OBJECT(); if (PHAR_G(readonly)) { - zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Phar is readonly, cannot change compression"); } #if HAVE_BZ2 if (!pharobj_cancompress(&phar_obj->arc.archive->manifest TSRMLS_CC)) { - zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress all files as Bzip2, some are compressed as gzip and cannot be uncompressed"); } pharobj_set_compression(&phar_obj->arc.archive->manifest, PHAR_ENT_COMPRESSED_BZ2 TSRMLS_CC); @@ -450,11 +450,11 @@ PHP_METHOD(Phar, compressAllFilesBZIP2) phar_flush(phar_obj->arc.archive, 0, 0, &error TSRMLS_CC); if (error) { - zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, error); + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, error); efree(error); } #else - zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress with Bzip2 compression, bz2 extension is not enabled"); #endif } @@ -469,11 +469,11 @@ PHP_METHOD(Phar, uncompressAllFiles) PHAR_ARCHIVE_OBJECT(); if (PHAR_G(readonly)) { - zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Phar is readonly, cannot change compression"); } if (!pharobj_cancompress(&phar_obj->arc.archive->manifest TSRMLS_CC)) { - zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot uncompress all files, some are compressed as bzip2 or gzip and cannot be uncompressed"); } pharobj_set_compression(&phar_obj->arc.archive->manifest, PHAR_ENT_COMPRESSED_NONE TSRMLS_CC); @@ -481,7 +481,7 @@ PHP_METHOD(Phar, uncompressAllFiles) phar_flush(phar_obj->arc.archive, 0, 0, &error TSRMLS_CC); if (error) { - zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, error); + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, error); efree(error); } } diff --git a/ext/phar/tests/017.phpt b/ext/phar/tests/017.phpt index 9be69708c4..a0c1926de7 100644 --- a/ext/phar/tests/017.phpt +++ b/ext/phar/tests/017.phpt @@ -22,4 +22,4 @@ $dir = opendir('phar://hio'); --CLEAN-- --EXPECTF-- -Warning: opendir(phar://hio): failed to open dir: phar error: no directory in "phar://hio", must have at least phar://hio/ for root directory in %s on line %d +Warning: opendir(phar://hio): failed to open dir: phar error: no directory in "phar://hio", must have at least phar://hio/ for root directory (always use full path to a new phar) in %s on line %d diff --git a/ext/phar/tests/phar_create_in_cwd.phpt b/ext/phar/tests/phar_create_in_cwd.phpt index aed04c68df..b10bf4971c 100644 --- a/ext/phar/tests/phar_create_in_cwd.phpt +++ b/ext/phar/tests/phar_create_in_cwd.phpt @@ -1,5 +1,5 @@ --TEST-- -Phar: create a Phar with relative path +Phar: attempt to create a Phar with relative path --SKIPIF-- --INI-- @@ -8,11 +8,12 @@ phar.readonly=0 --FILE-- commit(); -var_dump($p->getStub()); -$p->setStub("commit(); + var_dump($p->getStub()); + $p->setStub(""); -var_dump($p->getStub()); + var_dump($p->getStub()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} ?> ===DONE=== --CLEAN-- @@ -29,14 +33,5 @@ var_dump($p->getStub()); unlink(dirname(__FILE__) . '/brandnewphar.phar'); ?> --EXPECT-- -string(24) "" +RecursiveDirectoryIterator::__construct(phar://brandnewphar.phar): failed to open dir: phar error: no directory in "phar://brandnewphar.phar", must have at least phar://brandnewphar.phar/ for root directory (always use full path to a new phar) ===DONE=== \ No newline at end of file