]> granicus.if.org Git - php/commitdiff
fix mem leak on error, fix cwd issue. go back to BadMethodCallException for Phar...
authorGreg Beaver <cellog@php.net>
Sat, 3 Feb 2007 04:04:18 +0000 (04:04 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 3 Feb 2007 04:04:18 +0000 (04:04 +0000)
ext/phar/TODO
ext/phar/phar.c
ext/phar/phar_object.c
ext/phar/tests/017.phpt
ext/phar/tests/phar_create_in_cwd.phpt

index 878a2b44776e7aa7fac046ae3374571e01276552..6bf549a6b33449cc8aa85ca4675966dfd4809752 100644 (file)
@@ -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
 
index 1a8d590df291e28ba00ef11dd038ec9abba15bd4..989dbe2cae48f9deae8fb71162f68ef60db6d64f 100644 (file)
@@ -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;
                }
index 6935055e0a104f062871adfc85a4f8f9010614fb..644fd36f36cb37d1cb197f7908112d2d085c6939 100755 (executable)
@@ -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);
        }
 }
index 9be69708c4812d80955d5a07fb1bb90c2086923d..a0c1926de7717b67a3941a4586c292e0da6ec296 100644 (file)
@@ -22,4 +22,4 @@ $dir = opendir('phar://hio');
 --CLEAN--
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
 --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
index aed04c68df4831d6da4281f341292c93ca15ecec..b10bf4971c2e94820b68e807c5c41ad5019c6935 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-Phar: create a Phar with relative path
+Phar: attempt to create a Phar with relative path
 --SKIPIF--
 <?php if (!extension_loaded("phar")) print "skip"; ?>
 --INI--
@@ -8,11 +8,12 @@ phar.readonly=0
 --FILE--
 <?php
 chdir(dirname(__FILE__));
-$p = new Phar('brandnewphar.phar');
-$p['file1.txt'] = 'hi';
-$p->commit();
-var_dump($p->getStub());
-$p->setStub("<?php
+try {
+       $p = new Phar('brandnewphar.phar');
+       $p['file1.txt'] = 'hi';
+       $p->commit();
+       var_dump($p->getStub());
+       $p->setStub("<?php
 function __autoload(\$class)
 {
     include 'phar://' . str_replace('_', '/', \$class);
@@ -21,7 +22,10 @@ Phar::mapPhar('brandnewphar.phar');
 include 'phar://brandnewphar.phar/startup.php';
 __HALT_COMPILER();
 ?>");
-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) "<?php __HALT_COMPILER();"
-string(198) "<?php
-function __autoload($class)
-{
-    include 'phar://' . str_replace('_', '/', $class);
-}
-Phar::mapPhar('brandnewphar.phar');
-include 'phar://brandnewphar.phar/startup.php';
-__HALT_COMPILER();
-?>"
+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