@@ -262,9 +262,11 @@ static void dba_close(dba_info *info)
262262 if (info -> hnd ) {
263263 info -> hnd -> close (info );
264264 }
265- if (info -> path ) {
266- pefree (info -> path , info -> flags & DBA_PERSISTENT );
267- }
265+ ZEND_ASSERT (info -> path );
266+ // Cannot use zend_string_release_ex(info->path, info->flags&DBA_PERSISTENT); as this fails GC assertion?
267+ zend_string_free (info -> path );
268+ info -> path = NULL ;
269+
268270 if (info -> fp && info -> fp != info -> lock .fp ) {
269271 if (info -> flags & DBA_PERSISTENT ) {
270272 php_stream_pclose (info -> fp );
@@ -431,7 +433,7 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode)
431433/* }}} */
432434
433435/* {{{ php_find_dbm */
434- static dba_info * php_dba_find (const char * path )
436+ static dba_info * php_dba_find (const zend_string * path )
435437{
436438 zend_resource * le ;
437439 dba_info * info ;
@@ -444,7 +446,7 @@ static dba_info *php_dba_find(const char* path)
444446 }
445447 if (le -> type == le_db || le -> type == le_pdb ) {
446448 info = (dba_info * )(le -> ptr );
447- if (! strcmp ( info -> path , path )) {
449+ if (zend_string_equals ( path , info -> path )) {
448450 return (dba_info * )(le -> ptr );
449451 }
450452 }
@@ -467,7 +469,6 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
467469 const char * file_mode ;
468470 const char * lock_file_mode = NULL ;
469471 int persistent_flag = persistent ? STREAM_OPEN_PERSISTENT : 0 ;
470- zend_string * opened_path = NULL ;
471472 char * lock_name ;
472473#ifdef PHP_WIN32
473474 bool restarted = 0 ;
@@ -724,7 +725,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
724725
725726 info = pemalloc (sizeof (dba_info ), persistent );
726727 memset (info , 0 , sizeof (dba_info ));
727- info -> path = pestrdup ( ZSTR_VAL ( path ) , persistent );
728+ info -> path = zend_string_dup ( path , persistent );
728729 info -> mode = modenr ;
729730 info -> file_permission = permission ;
730731 info -> map_size = map_size ;
@@ -753,8 +754,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
753754 if (is_db_lock ) {
754755 lock_name = ZSTR_VAL (path );
755756 } else {
756- spprintf (& lock_name , 0 , "%s.lck" , info -> path );
757+ spprintf (& lock_name , 0 , "%s.lck" , ZSTR_VAL ( info -> path ) );
757758 if (!strcmp (file_mode , "r" )) {
759+ zend_string * opened_path = NULL ;
758760 /* when in read only mode try to use existing .lck file first */
759761 /* do not log errors for .lck file while in read only mode on .lck file */
760762 lock_file_mode = "rb" ;
@@ -769,13 +771,17 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
769771 }
770772 }
771773 if (!info -> lock .fp ) {
774+ zend_string * opened_path = NULL ;
772775 info -> lock .fp = php_stream_open_wrapper (lock_name , lock_file_mode , STREAM_MUST_SEEK |REPORT_ERRORS |IGNORE_PATH |persistent_flag , & opened_path );
773776 if (info -> lock .fp ) {
774777 if (is_db_lock ) {
778+ ZEND_ASSERT (opened_path );
775779 /* replace the path info with the real path of the opened file */
776- pefree (info -> path , persistent );
777- info -> path = pestrndup ( ZSTR_VAL ( opened_path ), ZSTR_LEN ( opened_path ) , persistent );
780+ zend_string_release_ex (info -> path , persistent );
781+ info -> path = zend_string_dup ( opened_path , persistent );
778782 }
783+ }
784+ if (opened_path ) {
779785 zend_string_release_ex (opened_path , 0 );
780786 }
781787 }
@@ -801,7 +807,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
801807 if (info -> lock .fp && is_db_lock ) {
802808 info -> fp = info -> lock .fp ; /* use the same stream for locking and database access */
803809 } else {
804- info -> fp = php_stream_open_wrapper (info -> path , file_mode , STREAM_MUST_SEEK |REPORT_ERRORS |IGNORE_PATH |persistent_flag , NULL );
810+ info -> fp = php_stream_open_wrapper (ZSTR_VAL ( info -> path ) , file_mode , STREAM_MUST_SEEK |REPORT_ERRORS |IGNORE_PATH |persistent_flag , NULL );
805811 }
806812 if (!info -> fp ) {
807813 dba_close (info );
@@ -1207,7 +1213,7 @@ PHP_FUNCTION(dba_list)
12071213 }
12081214 if (le -> type == le_db || le -> type == le_pdb ) {
12091215 info = (dba_info * )(le -> ptr );
1210- add_index_string (return_value , i , info -> path );
1216+ add_index_str (return_value , i , zend_string_copy ( info -> path ) );
12111217 }
12121218 }
12131219}
0 commit comments