@@ -256,14 +256,14 @@ static void dba_close_info(dba_info *info)
256
256
if (info -> flags & DBA_PERSISTENT ) {
257
257
php_stream_pclose (info -> fp );
258
258
} else {
259
- php_stream_close (info -> fp );
259
+ php_stream_free (info -> fp , PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR );
260
260
}
261
261
}
262
262
if (info -> lock .fp ) {
263
263
if (info -> flags & DBA_PERSISTENT ) {
264
264
php_stream_pclose (info -> lock .fp );
265
265
} else {
266
- php_stream_close (info -> lock .fp );
266
+ php_stream_free (info -> lock .fp , PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR );
267
267
}
268
268
}
269
269
@@ -516,6 +516,17 @@ static zend_always_inline zend_string *php_dba_zend_string_dup_safe(zend_string
516
516
}
517
517
}
518
518
519
+ /* See mysqlnd_fixup_regular_list */
520
+ static void php_dba_fixup_regular_list (php_stream * stream )
521
+ {
522
+ dtor_func_t origin_dtor = EG (regular_list ).pDestructor ;
523
+ EG (regular_list ).pDestructor = NULL ;
524
+ zend_hash_index_del (& EG (regular_list ), stream -> res -> handle );
525
+ EG (regular_list ).pDestructor = origin_dtor ;
526
+ efree (stream -> res );
527
+ stream -> res = NULL ;
528
+ }
529
+
519
530
/* {{{ php_dba_open */
520
531
static void php_dba_open (INTERNAL_FUNCTION_PARAMETERS , bool persistent )
521
532
{
@@ -827,6 +838,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
827
838
/* do not log errors for .lck file while in read only mode on .lck file */
828
839
lock_file_mode = "rb" ;
829
840
connection -> info -> lock .fp = php_stream_open_wrapper (lock_name , lock_file_mode , STREAM_MUST_SEEK |IGNORE_PATH |persistent_flag , NULL );
841
+ if (connection -> info -> lock .fp && !persistent_flag ) {
842
+ php_dba_fixup_regular_list (connection -> info -> lock .fp );
843
+ }
830
844
}
831
845
if (!connection -> info -> lock .fp ) {
832
846
/* when not in read mode or failed to open .lck file read only. now try again in create(write) mode and log errors */
@@ -837,6 +851,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
837
851
zend_string * opened_path = NULL ;
838
852
connection -> info -> lock .fp = php_stream_open_wrapper (lock_name , lock_file_mode , STREAM_MUST_SEEK |REPORT_ERRORS |IGNORE_PATH |persistent_flag , & opened_path );
839
853
if (connection -> info -> lock .fp ) {
854
+ if (!persistent_flag ) {
855
+ php_dba_fixup_regular_list (connection -> info -> lock .fp );
856
+ }
840
857
if (is_db_lock ) {
841
858
if (opened_path ) {
842
859
/* replace the path info with the real path of the opened file */
@@ -873,6 +890,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
873
890
connection -> info -> fp = connection -> info -> lock .fp ; /* use the same stream for locking and database access */
874
891
} else {
875
892
connection -> info -> fp = php_stream_open_wrapper (ZSTR_VAL (connection -> info -> path ), file_mode , STREAM_MUST_SEEK |REPORT_ERRORS |IGNORE_PATH |persistent_flag , NULL );
893
+ if (connection -> info -> fp && !persistent_flag ) {
894
+ php_dba_fixup_regular_list (connection -> info -> fp );
895
+ }
876
896
}
877
897
if (!connection -> info -> fp ) {
878
898
/* stream operation already wrote an error message */
0 commit comments