File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -4504,6 +4504,9 @@ PHP_METHOD(PharFileInfo, __construct)
45044504 efree (entry );
45054505
45064506 entry_obj -> entry = entry_info ;
4507+ if (!entry_info -> is_persistent && !entry_info -> is_temp_dir ) {
4508+ ++ entry_info -> fp_refcount ;
4509+ }
45074510
45084511 ZVAL_STRINGL (& arg1 , fname , fname_len );
45094512
@@ -4533,15 +4536,23 @@ PHP_METHOD(PharFileInfo, __destruct)
45334536 RETURN_THROWS ();
45344537 }
45354538
4536- if (entry_obj -> entry && entry_obj -> entry -> is_temp_dir ) {
4539+ if (!entry_obj -> entry ) {
4540+ return ;
4541+ }
4542+
4543+ if (entry_obj -> entry -> is_temp_dir ) {
45374544 if (entry_obj -> entry -> filename ) {
45384545 zend_string_efree (entry_obj -> entry -> filename );
45394546 entry_obj -> entry -> filename = NULL ;
45404547 }
45414548
45424549 efree (entry_obj -> entry );
4543- entry_obj -> entry = NULL ;
4550+ } else if (!entry_obj -> entry -> is_persistent ) {
4551+ -- entry_obj -> entry -> fp_refcount ;
4552+ /* It is necessarily still in the manifest, which will ultimately free this. */
45444553 }
4554+
4555+ entry_obj -> entry = NULL ;
45454556}
45464557/* }}} */
45474558
Original file line number Diff line number Diff line change 1+ --TEST--
2+ GH-17808 (PharFileInfo refcount bug)
3+ --EXTENSIONS--
4+ phar
5+ --FILE--
6+ <?php
7+ $ fname = __DIR__ .'/tar/files/Structures_Graph-1.0.3.tgz ' ;
8+ $ tar = new PharData ($ fname );
9+ foreach (new RecursiveIteratorIterator ($ tar ) as $ file ) {
10+ }
11+ var_dump ("$ file " );
12+ var_dump (strlen ($ file ->getContent ()));
13+ unlink ("$ file " );
14+ var_dump ($ file ->getATime ());
15+ ?>
16+ --EXPECTF--
17+ string(%d) "phar://%spackage.xml"
18+ int(6747)
19+
20+ Warning: unlink(): phar error: "package.xml" in phar %s, has open file pointers, cannot unlink in %s on line %d
21+ int(33188)
You can’t perform that action at this time.
0 commit comments