@@ -569,36 +569,33 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
569
569
RETURN_THROWS ();
570
570
}
571
571
572
- char * resource_key ;
573
- size_t resource_key_len = spprintf (& resource_key , 0 ,
572
+ zend_string * resource_key = zend_strpprintf (0 ,
574
573
"dba_%d_%s_%s_%s" , persistent , ZSTR_VAL (path ), ZSTR_VAL (mode ), handler_str ? ZSTR_VAL (handler_str ) : ""
575
574
);
576
575
577
576
if (persistent ) {
578
577
zend_resource * le ;
579
578
580
579
/* try to find if we already have this link in our persistent list */
581
- if ((le = zend_hash_str_find_ptr (& EG (persistent_list ), resource_key , resource_key_len )) != NULL ) {
580
+ if ((le = zend_hash_find_ptr (& EG (persistent_list ), resource_key )) != NULL ) {
582
581
if (le -> type != le_pdb ) {
583
582
// TODO This should never happen
584
- efree (resource_key );
583
+ zend_string_release_ex (resource_key , /* persistent */ false );
585
584
RETURN_FALSE ;
586
585
}
587
586
588
587
object_init_ex (return_value , dba_connection_ce );
589
588
dba_connection * connection = Z_DBA_CONNECTION_P (return_value );
590
589
connection -> info = (dba_info * )le -> ptr ;
591
- connection -> hash = zend_string_init (resource_key , resource_key_len , persistent );
592
- if (persistent ) {
593
- GC_MAKE_PERSISTENT_LOCAL (connection -> hash );
594
- }
590
+ connection -> hash = zend_string_dup (resource_key , /* persistent */ true);
591
+ GC_MAKE_PERSISTENT_LOCAL (connection -> hash );
595
592
596
593
if (zend_hash_exists (& DBA_G (connections ), connection -> hash )) {
597
594
zend_hash_del (& DBA_G (connections ), connection -> hash );
598
595
}
599
596
600
597
zend_hash_add_new (& DBA_G (connections ), connection -> hash , return_value );
601
- efree (resource_key );
598
+ zend_string_release_ex (resource_key , /* persistent */ false );
602
599
return ;
603
600
}
604
601
}
@@ -607,7 +604,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
607
604
hptr = DBA_G (default_hptr );
608
605
if (!hptr ) {
609
606
php_error_docref (NULL , E_WARNING , "No default handler selected" );
610
- efree (resource_key );
607
+ zend_string_release_ex (resource_key , /* persistent */ false );
611
608
RETURN_FALSE ;
612
609
}
613
610
ZEND_ASSERT (hptr -> name );
@@ -617,7 +614,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
617
614
618
615
if (!hptr -> name ) {
619
616
php_error_docref (NULL , E_WARNING , "Handler \"%s\" is not available" , ZSTR_VAL (handler_str ));
620
- efree (resource_key );
617
+ zend_string_release_ex (resource_key , /* persistent */ false );
621
618
RETURN_FALSE ;
622
619
}
623
620
}
@@ -641,13 +638,13 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
641
638
642
639
if (ZSTR_LEN (mode ) > 3 ) {
643
640
zend_argument_value_error (2 , "must be at most 3 characters" );
644
- efree (resource_key );
641
+ zend_string_release_ex (resource_key , /* persistent */ false );
645
642
RETURN_THROWS ();
646
643
}
647
644
if (ZSTR_LEN (mode ) == 3 ) {
648
645
if (ZSTR_VAL (mode )[2 ] != 't' ) {
649
646
zend_argument_value_error (2 , "third character must be \"t\"" );
650
- efree (resource_key );
647
+ zend_string_release_ex (resource_key , /* persistent */ false );
651
648
RETURN_THROWS ();
652
649
}
653
650
is_test_lock = true;
@@ -660,7 +657,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
660
657
case '-' :
661
658
if ((hptr -> flags & DBA_LOCK_ALL ) == 0 ) {
662
659
php_error_docref (NULL , E_WARNING , "Locking cannot be disabled for handler %s" , hptr -> name );
663
- efree (resource_key );
660
+ zend_string_release_ex (resource_key , /* persistent */ false );
664
661
RETURN_FALSE ;
665
662
}
666
663
is_lock_ignored = true;
@@ -682,7 +679,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
682
679
break ;
683
680
default :
684
681
zend_argument_value_error (2 , "second character must be one of \"d\", \"l\", \"-\", or \"t\"" );
685
- efree (resource_key );
682
+ zend_string_release_ex (resource_key , /* persistent */ false );
686
683
RETURN_THROWS ();
687
684
}
688
685
} else {
@@ -751,7 +748,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
751
748
break ;
752
749
default :
753
750
zend_argument_value_error (2 , "first character must be one of \"r\", \"w\", \"c\", or \"n\"" );
754
- efree (resource_key );
751
+ zend_string_release_ex (resource_key , /* persistent */ false );
755
752
RETURN_THROWS ();
756
753
}
757
754
if (!lock_file_mode ) {
@@ -760,17 +757,17 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
760
757
if (is_test_lock ) {
761
758
if (is_lock_ignored ) {
762
759
zend_argument_value_error (2 , "cannot combine mode \"-\" (no lock) and \"t\" (test lock)" );
763
- efree (resource_key );
760
+ zend_string_release_ex (resource_key , /* persistent */ false );
764
761
RETURN_THROWS ();
765
762
}
766
763
if (!lock_mode ) {
767
764
if ((hptr -> flags & DBA_LOCK_ALL ) == 0 ) {
768
765
php_error_docref (NULL , E_WARNING , "Handler %s uses its own locking which doesn't support mode modifier t (test lock)" , hptr -> name );
769
- efree (resource_key );
766
+ zend_string_release_ex (resource_key , /* persistent */ false );
770
767
RETURN_FALSE ;
771
768
} else {
772
769
php_error_docref (NULL , E_WARNING , "Handler %s doesn't uses locking for this mode which makes modifier t (test lock) obsolete" , hptr -> name );
773
- efree (resource_key );
770
+ zend_string_release_ex (resource_key , /* persistent */ false );
774
771
RETURN_FALSE ;
775
772
}
776
773
} else {
@@ -780,7 +777,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
780
777
781
778
zval * connection_zval ;
782
779
dba_connection * connection ;
783
- if ((connection_zval = zend_hash_str_find (& DBA_G (connections ), resource_key , resource_key_len )) == NULL ) {
780
+ if ((connection_zval = zend_hash_find (& DBA_G (connections ), resource_key )) == NULL ) {
784
781
object_init_ex (return_value , dba_connection_ce );
785
782
connection = Z_DBA_CONNECTION_P (return_value );
786
783
@@ -792,9 +789,11 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
792
789
connection -> info -> driver_flags = driver_flags ;
793
790
connection -> info -> flags = (hptr -> flags & ~DBA_LOCK_ALL ) | (lock_flag & DBA_LOCK_ALL ) | (persistent ? DBA_PERSISTENT : 0 );
794
791
connection -> info -> lock .mode = lock_mode ;
795
- connection -> hash = zend_string_init (resource_key , resource_key_len , persistent );
796
792
if (persistent ) {
793
+ connection -> hash = zend_string_dup (resource_key , /* persistent */ true);
797
794
GC_MAKE_PERSISTENT_LOCAL (connection -> hash );
795
+ } else {
796
+ connection -> hash = zend_string_copy (resource_key );
798
797
}
799
798
} else {
800
799
ZVAL_COPY (return_value , connection_zval );
@@ -860,7 +859,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
860
859
}
861
860
if (!connection -> info -> lock .fp ) {
862
861
/* stream operation already wrote an error message */
863
- efree (resource_key );
862
+ zend_string_release_ex (resource_key , /* persistent */ false );
864
863
zval_ptr_dtor (return_value );
865
864
RETURN_FALSE ;
866
865
}
@@ -881,7 +880,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
881
880
}
882
881
if (!connection -> info -> fp ) {
883
882
/* stream operation already wrote an error message */
884
- efree (resource_key );
883
+ zend_string_release_ex (resource_key , /* persistent */ false );
885
884
zval_ptr_dtor (return_value );
886
885
RETURN_FALSE ;
887
886
}
@@ -891,7 +890,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
891
890
*/
892
891
if (SUCCESS != php_stream_cast (connection -> info -> fp , PHP_STREAM_AS_FD , (void * )& connection -> info -> fd , 1 )) {
893
892
php_error_docref (NULL , E_WARNING , "Could not cast stream" );
894
- efree (resource_key );
893
+ zend_string_release_ex (resource_key , /* persistent */ false );
895
894
zval_ptr_dtor (return_value );
896
895
RETURN_FALSE ;
897
896
#ifdef F_SETFL
@@ -927,24 +926,24 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
927
926
php_error_docref (NULL , E_WARNING , "Driver initialization failed for handler: %s" , hptr -> name );
928
927
}
929
928
}
930
- efree (resource_key );
929
+ zend_string_release_ex (resource_key , /* persistent */ false );
931
930
zval_ptr_dtor (return_value );
932
931
RETURN_FALSE ;
933
932
}
934
933
935
934
connection -> info -> hnd = hptr ;
936
935
937
936
if (persistent ) {
938
- if (zend_register_persistent_resource ( resource_key , resource_key_len , connection -> info , le_pdb ) == NULL ) {
937
+ if (zend_register_persistent_resource_ex ( connection -> hash , connection -> info , le_pdb ) == NULL ) {
939
938
php_error_docref (NULL , E_WARNING , "Could not register persistent resource" );
940
- efree (resource_key );
939
+ zend_string_release_ex (resource_key , /* persistent */ false );
941
940
zval_ptr_dtor (return_value );
942
941
RETURN_FALSE ;
943
942
}
944
943
}
945
944
946
945
zend_hash_add_new (& DBA_G (connections ), connection -> hash , return_value );
947
- efree (resource_key );
946
+ zend_string_release_ex (resource_key , /* persistent */ false );
948
947
}
949
948
/* }}} */
950
949
0 commit comments