Commit 7d166a2f8eb for php.net
commit 7d166a2f8ebb4bb55e6b3c6e4e0e512c041d0373
Author: Gina Peter Banyard <girgias@php.net>
Date: Fri Apr 24 14:08:13 2026 +0100
ext/phar: no need to free error if operation is successful (#21859)
This could also be seen from the lack of coverage on CodeCov as these are impossible branches to reach.
diff --git a/ext/phar/dirstream.c b/ext/phar/dirstream.c
index bdd90851fec..4bef14dfe6a 100644
--- a/ext/phar/dirstream.c
+++ b/ext/phar/dirstream.c
@@ -287,10 +287,6 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path,
return NULL;
}
- if (error) {
- efree(error);
- }
-
if (zend_string_equals(resource->path, ZSTR_CHAR('/'))) {
/* root directory requested */
php_url_free(resource);
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index c07ff93b951..bc55c175f7b 100644
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -1655,9 +1655,6 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
return ZEND_HASH_APPLY_STOP;
} else {
- if (error) {
- efree(error);
- }
/* convert to PHAR_UFP */
if (data->internal_file->fp_type == PHAR_MOD) {
php_stream_close(data->internal_file->fp);
@@ -3603,10 +3600,6 @@ static void phar_add_file(phar_archive_data **pphar, zend_string *file_name, con
}
goto finish;
} else {
- if (error) {
- efree(error);
- }
-
if (!data->internal_file->is_dir) {
size_t contents_len = 0;
if (content) {
@@ -3683,10 +3676,6 @@ static void phar_mkdir(phar_archive_data **pphar, zend_string *dir_name)
return;
} else {
- if (error) {
- efree(error);
- }
-
/* check for copy on write */
if (data->phar != *pphar) {
*pphar = data->phar;
diff --git a/ext/phar/stream.c b/ext/phar/stream.c
index 1d9229c4462..f49bc5e2deb 100644
--- a/ext/phar/stream.c
+++ b/ext/phar/stream.c
@@ -200,9 +200,6 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
php_url_free(resource);
return NULL;
}
- if (error) {
- efree(error);
- }
fpf = php_stream_alloc(&phar_ops, idata, NULL, mode);
php_url_free(resource);
efree(internal_file);
@@ -706,9 +703,6 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
php_url_free(resource);
return 0;
}
- if (error) {
- efree(error);
- }
if (idata->internal_file->fp_refcount > 1) {
/* more than just our fp resource is open for this file */
php_stream_wrapper_log_error(wrapper, options, "phar error: \"%s\" in phar \"%s\", has open file pointers, cannot unlink", internal_file, ZSTR_VAL(resource->host));