From a1828999c58460ab2c6d8f0e08c9ac1cd2799d73 Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Sat, 23 Feb 2008 15:05:05 +0000 Subject: [PATCH] fix unfreed stuff when adding default stub --- ext/phar/tar.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ext/phar/tar.c b/ext/phar/tar.c index 4cef59a0b1..e4b750ecb9 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -534,11 +534,15 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er } } else { /* Either this is a brand new phar (add the stub), or setDefaultStub() is the caller (overwrite the stub) */ + if (!zend_hash_exists(&phar->manifest, ".phar/stub.php", sizeof(".phar/stub.php")-1)) { + goto no_default_stub; + } entry.fp = php_stream_fopen_tmpfile(); if (sizeof(newstub)-1 != php_stream_write(entry.fp, newstub, sizeof(newstub)-1)) { if (error) { spprintf(error, 0, "unable to %s stub in%star-based phar \"%s\", failed", user_stub ? "overwrite" : "create", user_stub ? " " : " new ", phar->fname); } + php_stream_close(entry.fp); return EOF; } entry.uncompressed_filesize = entry.compressed_filesize = sizeof(newstub) - 1; @@ -546,15 +550,13 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er entry.filename_len = sizeof(".phar/stub.php")-1; if (!user_stub) { - if (!zend_hash_exists(&phar->manifest, ".phar/stub.php", sizeof(".phar/stub.php")-1)) { - if (SUCCESS != zend_hash_add(&phar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) { - php_stream_close(entry.fp); - efree(entry.filename); - if (error) { - spprintf(error, 0, "unable to create stub in tar-based phar \"%s\"", phar->fname); - } - return EOF; + if (SUCCESS != zend_hash_add(&phar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) { + php_stream_close(entry.fp); + efree(entry.filename); + if (error) { + spprintf(error, 0, "unable to create stub in tar-based phar \"%s\"", phar->fname); } + return EOF; } } else { if (SUCCESS != zend_hash_update(&phar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) { @@ -567,7 +569,7 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er } } } - +no_default_stub: if (phar->fp && !phar->is_brandnew) { oldfile = phar->fp; closeoldfile = 0; -- 2.50.1