@@ -569,36 +569,33 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
569569		RETURN_THROWS ();
570570	}
571571
572- 	char  * resource_key ;
573- 	size_t  resource_key_len  =  spprintf (& resource_key , 0 ,
572+ 	zend_string  * resource_key  =  zend_strpprintf (0 ,
574573		"dba_%d_%s_%s_%s" , persistent , ZSTR_VAL (path ), ZSTR_VAL (mode ), handler_str  ? ZSTR_VAL (handler_str ) : "" 
575574	);
576575
577576	if  (persistent ) {
578577		zend_resource  * le ;
579578
580579		/* 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 ) {
582581			if  (le -> type  !=  le_pdb ) {
583582				// TODO This should never happen 
584- 				efree (resource_key );
583+ 				zend_string_release_ex (resource_key ,  /* persistent */  false );
585584				RETURN_FALSE ;
586585			}
587586
588587			object_init_ex (return_value , dba_connection_ce );
589588			dba_connection  * connection  =  Z_DBA_CONNECTION_P (return_value );
590589			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 );
595592
596593			if  (zend_hash_exists (& DBA_G (connections ), connection -> hash )) {
597594				zend_hash_del (& DBA_G (connections ), connection -> hash );
598595			}
599596
600597			zend_hash_add_new (& DBA_G (connections ), connection -> hash , return_value );
601- 			efree (resource_key );
598+ 			zend_string_release_ex (resource_key ,  /* persistent */  false );
602599			return ;
603600		}
604601	}
@@ -607,7 +604,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
607604		hptr  =  DBA_G (default_hptr );
608605		if  (!hptr ) {
609606			php_error_docref (NULL , E_WARNING , "No default handler selected" );
610- 			efree (resource_key );
607+ 			zend_string_release_ex (resource_key ,  /* persistent */  false );
611608			RETURN_FALSE ;
612609		}
613610		ZEND_ASSERT (hptr -> name );
@@ -617,7 +614,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
617614
618615		if  (!hptr -> name ) {
619616			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 );
621618			RETURN_FALSE ;
622619		}
623620	}
@@ -641,13 +638,13 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
641638
642639	if  (ZSTR_LEN (mode ) >  3 ) {
643640		zend_argument_value_error (2 , "must be at most 3 characters" );
644- 		efree (resource_key );
641+ 		zend_string_release_ex (resource_key ,  /* persistent */  false );
645642		RETURN_THROWS ();
646643	}
647644	if  (ZSTR_LEN (mode ) ==  3 ) {
648645		if  (ZSTR_VAL (mode )[2 ] !=  't' ) {
649646			zend_argument_value_error (2 , "third character must be \"t\"" );
650- 			efree (resource_key );
647+ 			zend_string_release_ex (resource_key ,  /* persistent */  false );
651648			RETURN_THROWS ();
652649		}
653650		is_test_lock  =  true;
@@ -660,7 +657,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
660657			case  '-' :
661658				if  ((hptr -> flags  &  DBA_LOCK_ALL ) ==  0 ) {
662659					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 );
664661					RETURN_FALSE ;
665662				}
666663				is_lock_ignored  =  true;
@@ -682,7 +679,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
682679				break ;
683680			default :
684681				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 );
686683				RETURN_THROWS ();
687684		}
688685	} else  {
@@ -751,7 +748,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
751748			break ;
752749		default :
753750			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 );
755752			RETURN_THROWS ();
756753	}
757754	if  (!lock_file_mode ) {
@@ -760,17 +757,17 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
760757	if  (is_test_lock ) {
761758		if  (is_lock_ignored ) {
762759			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 );
764761			RETURN_THROWS ();
765762		}
766763		if  (!lock_mode ) {
767764			if  ((hptr -> flags  &  DBA_LOCK_ALL ) ==  0 ) {
768765				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 );
770767				RETURN_FALSE ;
771768			} else  {
772769				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 );
774771				RETURN_FALSE ;
775772			}
776773		} else  {
@@ -780,7 +777,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
780777
781778	zval  * connection_zval ;
782779	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 ) {
784781		object_init_ex (return_value , dba_connection_ce );
785782		connection  =  Z_DBA_CONNECTION_P (return_value );
786783
@@ -792,9 +789,11 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
792789		connection -> info -> driver_flags  =  driver_flags ;
793790		connection -> info -> flags  =  (hptr -> flags  &  ~DBA_LOCK_ALL ) | (lock_flag  &  DBA_LOCK_ALL ) | (persistent  ? DBA_PERSISTENT  : 0 );
794791		connection -> info -> lock .mode  =  lock_mode ;
795- 		connection -> hash  =  zend_string_init (resource_key , resource_key_len , persistent );
796792		if  (persistent ) {
793+ 			connection -> hash  =  zend_string_dup (resource_key , /* persistent */  true);
797794			GC_MAKE_PERSISTENT_LOCAL (connection -> hash );
795+ 		} else  {
796+ 			connection -> hash  =  zend_string_copy (resource_key );
798797		}
799798	} else  {
800799		ZVAL_COPY (return_value , connection_zval );
@@ -860,7 +859,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
860859		}
861860		if  (!connection -> info -> lock .fp ) {
862861			/* stream operation already wrote an error message */ 
863- 			efree (resource_key );
862+ 			zend_string_release_ex (resource_key ,  /* persistent */  false );
864863			zval_ptr_dtor (return_value );
865864			RETURN_FALSE ;
866865		}
@@ -881,7 +880,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
881880		}
882881		if  (!connection -> info -> fp ) {
883882			/* stream operation already wrote an error message */ 
884- 			efree (resource_key );
883+ 			zend_string_release_ex (resource_key ,  /* persistent */  false );
885884			zval_ptr_dtor (return_value );
886885			RETURN_FALSE ;
887886		}
@@ -891,7 +890,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
891890			 */ 
892891			if  (SUCCESS  !=  php_stream_cast (connection -> info -> fp , PHP_STREAM_AS_FD , (void * )& connection -> info -> fd , 1 )) {
893892				php_error_docref (NULL , E_WARNING , "Could not cast stream" );
894- 				efree (resource_key );
893+ 				zend_string_release_ex (resource_key ,  /* persistent */  false );
895894				zval_ptr_dtor (return_value );
896895				RETURN_FALSE ;
897896#ifdef  F_SETFL 
@@ -927,24 +926,24 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
927926				php_error_docref (NULL , E_WARNING , "Driver initialization failed for handler: %s" , hptr -> name );
928927			}
929928		}
930- 		efree (resource_key );
929+ 		zend_string_release_ex (resource_key ,  /* persistent */  false );
931930		zval_ptr_dtor (return_value );
932931		RETURN_FALSE ;
933932	}
934933
935934	connection -> info -> hnd  =  hptr ;
936935
937936	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 ) {
939938			php_error_docref (NULL , E_WARNING , "Could not register persistent resource" );
940- 			efree (resource_key );
939+ 			zend_string_release_ex (resource_key ,  /* persistent */  false );
941940			zval_ptr_dtor (return_value );
942941			RETURN_FALSE ;
943942		}
944943	}
945944
946945	zend_hash_add_new (& DBA_G (connections ), connection -> hash , return_value );
947- 	efree (resource_key );
946+ 	zend_string_release_ex (resource_key ,  /* persistent */  false );
948947}
949948/* }}} */ 
950949
0 commit comments