@@ -4391,6 +4391,9 @@ PHP_METHOD(PharFileInfo, __construct)
43914391 entry_obj -> entry = entry_info ;
43924392 if (!entry_info -> is_persistent && !entry_info -> is_temp_dir ) {
43934393 ++ entry_info -> fp_refcount ;
4394+ /* The phar data must exist to keep the alias locked. */
4395+ ZEND_ASSERT (!phar_data -> is_persistent );
4396+ ++ phar_data -> refcount ;
43944397 }
43954398
43964399 ZVAL_STRINGL (& arg1 , fname , fname_len );
@@ -4421,19 +4424,23 @@ PHP_METHOD(PharFileInfo, __destruct)
44214424
44224425 PHAR_ENTRY_OBJECT_EX (false);
44234426
4424- if (entry_obj -> entry -> is_temp_dir ) {
4425- if (entry_obj -> entry -> filename ) {
4426- zend_string_efree (entry_obj -> entry -> filename );
4427- entry_obj -> entry -> filename = NULL ;
4427+ phar_entry_info * entry = entry_obj -> entry ;
4428+
4429+ if (entry -> is_temp_dir ) {
4430+ if (entry -> filename ) {
4431+ zend_string_release_ex (entry -> filename , false);
4432+ entry -> filename = NULL ;
44284433 }
44294434
4430- efree (entry_obj -> entry );
4431- } else if (!entry_obj -> entry -> is_persistent ) {
4432- -- entry_obj -> entry -> fp_refcount ;
4433- /* It is necessarily still in the manifest, which will ultimately free this. */
4435+ efree (entry );
4436+ entry_obj -> entry = NULL ;
4437+ } else if (!entry -> is_persistent ) {
4438+ -- entry -> fp_refcount ;
4439+ /* The entry itself still lives in the manifest,
4440+ * which will either be freed here if the file info was the last reference; or freed later. */
4441+ entry_obj -> entry = NULL ;
4442+ phar_archive_delref (entry -> phar );
44344443 }
4435-
4436- entry_obj -> entry = NULL ;
44374444}
44384445/* }}} */
44394446
0 commit comments