@@ -262,9 +262,11 @@ static void dba_close(dba_info *info)
262
262
if (info -> hnd ) {
263
263
info -> hnd -> close (info );
264
264
}
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
+
268
270
if (info -> fp && info -> fp != info -> lock .fp ) {
269
271
if (info -> flags & DBA_PERSISTENT ) {
270
272
php_stream_pclose (info -> fp );
@@ -431,7 +433,7 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode)
431
433
/* }}} */
432
434
433
435
/* {{{ php_find_dbm */
434
- static dba_info * php_dba_find (const char * path )
436
+ static dba_info * php_dba_find (const zend_string * path )
435
437
{
436
438
zend_resource * le ;
437
439
dba_info * info ;
@@ -444,7 +446,7 @@ static dba_info *php_dba_find(const char* path)
444
446
}
445
447
if (le -> type == le_db || le -> type == le_pdb ) {
446
448
info = (dba_info * )(le -> ptr );
447
- if (! strcmp ( info -> path , path )) {
449
+ if (zend_string_equals ( path , info -> path )) {
448
450
return (dba_info * )(le -> ptr );
449
451
}
450
452
}
@@ -467,7 +469,6 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
467
469
const char * file_mode ;
468
470
const char * lock_file_mode = NULL ;
469
471
int persistent_flag = persistent ? STREAM_OPEN_PERSISTENT : 0 ;
470
- zend_string * opened_path = NULL ;
471
472
char * lock_name ;
472
473
#ifdef PHP_WIN32
473
474
bool restarted = 0 ;
@@ -724,7 +725,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
724
725
725
726
info = pemalloc (sizeof (dba_info ), persistent );
726
727
memset (info , 0 , sizeof (dba_info ));
727
- info -> path = pestrdup ( ZSTR_VAL ( path ) , persistent );
728
+ info -> path = zend_string_dup ( path , persistent );
728
729
info -> mode = modenr ;
729
730
info -> file_permission = permission ;
730
731
info -> map_size = map_size ;
@@ -753,8 +754,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
753
754
if (is_db_lock ) {
754
755
lock_name = ZSTR_VAL (path );
755
756
} else {
756
- spprintf (& lock_name , 0 , "%s.lck" , info -> path );
757
+ spprintf (& lock_name , 0 , "%s.lck" , ZSTR_VAL ( info -> path ) );
757
758
if (!strcmp (file_mode , "r" )) {
759
+ zend_string * opened_path = NULL ;
758
760
/* when in read only mode try to use existing .lck file first */
759
761
/* do not log errors for .lck file while in read only mode on .lck file */
760
762
lock_file_mode = "rb" ;
@@ -769,13 +771,17 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
769
771
}
770
772
}
771
773
if (!info -> lock .fp ) {
774
+ zend_string * opened_path = NULL ;
772
775
info -> lock .fp = php_stream_open_wrapper (lock_name , lock_file_mode , STREAM_MUST_SEEK |REPORT_ERRORS |IGNORE_PATH |persistent_flag , & opened_path );
773
776
if (info -> lock .fp ) {
774
777
if (is_db_lock ) {
778
+ ZEND_ASSERT (opened_path );
775
779
/* 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 );
778
782
}
783
+ }
784
+ if (opened_path ) {
779
785
zend_string_release_ex (opened_path , 0 );
780
786
}
781
787
}
@@ -801,7 +807,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
801
807
if (info -> lock .fp && is_db_lock ) {
802
808
info -> fp = info -> lock .fp ; /* use the same stream for locking and database access */
803
809
} 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 );
805
811
}
806
812
if (!info -> fp ) {
807
813
dba_close (info );
@@ -1207,7 +1213,7 @@ PHP_FUNCTION(dba_list)
1207
1213
}
1208
1214
if (le -> type == le_db || le -> type == le_pdb ) {
1209
1215
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 ) );
1211
1217
}
1212
1218
}
1213
1219
}
0 commit comments