#59467 closed defect (bug) (fixed)
Close ZIP archives before returning in `_unzip_file_ziparchive()`.
Reported by: | costdev | Owned by: | costdev |
---|---|---|---|
Milestone: | 6.4 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Filesystem API | Keywords: | has-patch |
Focuses: | performance | Cc: |
Description (last modified by )
In _unzip_file_ziparchive(), the archive is opened, but there are several returns that don't close the archive beforehand.
From the PHP manual on ZipArchive::close()
:
This method is automatically called at the end of the script.
Reference
and from the documentation for the underlying zip_close()
from libzip:
If successful, archive is freed. Otherwise archive is left unchanged and must still be freed.
Reference
As this function is used during installation and upgrade processes which are memory-intensive, let's free the archive before each of the return
statements, rather than waiting until the end of the script.
Note: The return
that gets used as a result of true !== $zopen
does not need a call to $z->close()
, as freeing the archive is handled internally by libzip's zip_open()
.
There are several early returns in
_unzip_file_ziparchive()
which don't close the archive prior to returning.As this function is used in installation and upgrade processes which are memory-intensive, this calls
ZipArchive::close()
to free the archive prior to each early return. This excludes the first return which is a result of a failure to open the archive, which is freed internally when the failure occurs.References: