From: Greg Beaver Date: Wed, 23 Apr 2008 18:30:53 +0000 (+0000) Subject: new test increases code coverage, fix memleak found by test X-Git-Tag: RELEASE_2_0_0b1~246 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b8fc7309f918888ce24cc37b0546c81bc5d6b3a;p=php new test increases code coverage, fix memleak found by test --- diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 294eee1466..bd07d96263 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -1699,10 +1699,12 @@ static zval *phar_rename_archive(phar_archive_data *phar, char *ext, zend_bool c efree(newname); if (zend_hash_exists(&(PHAR_GLOBALS->phar_fname_map), newpath, phar->fname_len)) { + efree(oldpath); zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Unable to add newly converted phar \"%s\" to the list of phars, a phar with that name already exists", phar->fname); return NULL; } if (SUCCESS != zend_hash_add(&(PHAR_GLOBALS->phar_fname_map), newpath, phar->fname_len, (void*)&phar, sizeof(phar_archive_data*), NULL)) { + efree(oldpath); zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Unable to add newly converted phar \"%s\" to the list of phars", phar->fname); return NULL; } @@ -1729,6 +1731,7 @@ static zval *phar_rename_archive(phar_archive_data *phar, char *ext, zend_bool c if (error) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, error); efree(error); + efree(oldpath); return NULL; } diff --git a/ext/phar/tests/phar_convert_again.phpt b/ext/phar/tests/phar_convert_again.phpt new file mode 100644 index 0000000000..bec5414e69 --- /dev/null +++ b/ext/phar/tests/phar_convert_again.phpt @@ -0,0 +1,60 @@ +--TEST-- +Phar::conversion to other formats +--SKIPIF-- + + + +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +'; +$file = $stub; + +$files = array(); +$files['a'] = 'a'; +$files['b'] = 'b'; +$files['c'] = 'c'; + +include 'files/phar_test.inc'; + +$phar = new Phar($fname); +$zip = $phar->convertToData(Phar::ZIP); +echo $zip->getPath() . "\n"; +$tgz = $phar->convertToData(Phar::TAR, Phar::GZ); +echo $tgz->getPath() . "\n"; +$tbz = $phar->convertToData(Phar::TAR, Phar::BZ2); +echo $tbz->getPath() . "\n"; +try { +$phar = $tbz->convertToExecutable(Phar::PHAR, Phar::NONE); +} catch (Exception $e) { +echo $e->getMessage() . "\n"; +} +copy($tbz->getPath(), $fname2); +$tbz = new PharData($fname2); +$phar = $tbz->convertToExecutable(Phar::PHAR, Phar::NONE); +echo $phar->getPath() . "\n"; +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +%sphar_convert_again.zip +%sphar_convert_again.tar.gz +%sphar_convert_again.tar.bz2 +Unable to add newly converted phar "%sphar_convert_again.phar" to the list of phars, a phar with that name already exists +%sphar_convert_again2.phar +===DONE===