@@ -264,6 +264,7 @@ static void dba_close(dba_info *info)
264264 }
265265 ZEND_ASSERT (info -> path );
266266 // Cannot use zend_string_release_ex(info->path, info->flags&DBA_PERSISTENT); as this fails GC assertion?
267+ // Zend/zend_rc_debug.c:38: void ZEND_RC_MOD_CHECK(const zend_refcounted_h *): Assertion `(zval_gc_flags(p->u.type_info) & ((1<<7)|(1<<8))) != (1<<7)' failed.
267268 zend_string_free (info -> path );
268269 info -> path = NULL ;
269270
@@ -456,6 +457,16 @@ static dba_info *php_dba_find(const zend_string *path)
456457}
457458/* }}} */
458459
460+ static zend_always_inline zend_string * php_dba_zend_string_dup_safe (zend_string * s , bool persistent )
461+ {
462+ if (ZSTR_IS_INTERNED (s ) && (!persistent || (GC_FLAGS (s ) & IS_STR_PERSISTENT ))) {
463+ return s ;
464+ } else {
465+ return zend_string_init (ZSTR_VAL (s ), ZSTR_LEN (s ), persistent );
466+ }
467+ }
468+
469+
459470#define FREE_PERSISTENT_RESOURCE_KEY () if (persistent_resource_key) {zend_string_release_ex(persistent_resource_key, false);}
460471
461472/* {{{ php_dba_open */
@@ -725,7 +736,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
725736
726737 info = pemalloc (sizeof (dba_info ), persistent );
727738 memset (info , 0 , sizeof (dba_info ));
728- info -> path = zend_string_dup (path , persistent );
739+ info -> path = php_dba_zend_string_dup_safe (path , persistent );
729740 info -> mode = modenr ;
730741 info -> file_permission = permission ;
731742 info -> map_size = map_size ;
@@ -777,8 +788,8 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
777788 if (is_db_lock ) {
778789 ZEND_ASSERT (opened_path );
779790 /* replace the path info with the real path of the opened file */
780- zend_string_release_ex (info -> path , persistent );
781- info -> path = zend_string_dup (opened_path , persistent );
791+ zend_string_release (info -> path );
792+ info -> path = php_dba_zend_string_dup_safe (opened_path , persistent );
782793 }
783794 }
784795 if (opened_path ) {
0 commit comments