@@ -4493,6 +4493,9 @@ PHP_METHOD(PharFileInfo, __construct)
44934493 entry_obj -> entry = entry_info ;
44944494 if (!entry_info -> is_persistent && !entry_info -> is_temp_dir ) {
44954495 ++ entry_info -> fp_refcount ;
4496+ /* The phar data must exist to keep the alias locked. */
4497+ ZEND_ASSERT (!phar_data -> is_persistent );
4498+ ++ phar_data -> refcount ;
44964499 }
44974500
44984501 ZVAL_STRINGL (& arg1 , fname , fname_len );
@@ -4523,23 +4526,26 @@ PHP_METHOD(PharFileInfo, __destruct)
45234526 RETURN_THROWS ();
45244527 }
45254528
4526- if (!entry_obj -> entry ) {
4529+ phar_entry_info * entry = entry_obj -> entry ;
4530+ if (!entry ) {
45274531 return ;
45284532 }
45294533
4530- if (entry_obj -> entry -> is_temp_dir ) {
4531- if (entry_obj -> entry -> filename ) {
4532- efree (entry_obj -> entry -> filename );
4533- entry_obj -> entry -> filename = NULL ;
4534+ if (entry -> is_temp_dir ) {
4535+ if (entry -> filename ) {
4536+ efree (entry -> filename );
4537+ entry -> filename = NULL ;
45344538 }
45354539
4536- efree (entry_obj -> entry );
4537- } else if (!entry_obj -> entry -> is_persistent ) {
4538- -- entry_obj -> entry -> fp_refcount ;
4539- /* It is necessarily still in the manifest, which will ultimately free this. */
4540+ efree (entry );
4541+ entry_obj -> entry = NULL ;
4542+ } else if (!entry -> is_persistent ) {
4543+ -- entry -> fp_refcount ;
4544+ /* The entry itself still lives in the manifest,
4545+ * which will either be freed here if the file info was the last reference; or freed later. */
4546+ entry_obj -> entry = NULL ;
4547+ phar_archive_delref (entry -> phar );
45404548 }
4541-
4542- entry_obj -> entry = NULL ;
45434549}
45444550/* }}} */
45454551
0 commit comments