11/* 
2-     +----------------------------------------------------------------------+
2+ +----------------------------------------------------------------------+ 
33   | Copyright (c) The PHP Group                                          | 
44   +----------------------------------------------------------------------+ 
55   | This source file is subject to version 3.01 of the PHP license,      | 
@@ -857,9 +857,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
857857		}
858858		if  (!connection -> info -> lock .fp ) {
859859			/* stream operation already wrote an error message */ 
860- 			zend_string_release_ex (resource_key , /* persistent */  false);
861- 			zval_ptr_dtor (return_value );
862- 			RETURN_FALSE ;
860+ 			goto fail ;
863861		}
864862		if  (!error  &&  !php_stream_supports_lock (connection -> info -> lock .fp )) {
865863			error  =  "Stream does not support locking" ;
@@ -878,19 +876,15 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
878876		}
879877		if  (!connection -> info -> fp ) {
880878			/* stream operation already wrote an error message */ 
881- 			zend_string_release_ex (resource_key , /* persistent */  false);
882- 			zval_ptr_dtor (return_value );
883- 			RETURN_FALSE ;
879+ 			goto fail ;
884880		}
885881		if  (hptr -> flags  &  (DBA_NO_APPEND |DBA_CAST_AS_FD )) {
886882			/* Needed because some systems do not allow to write to the original 
887883			 * file contents with O_APPEND being set. 
888884			 */ 
889885			if  (SUCCESS  !=  php_stream_cast (connection -> info -> fp , PHP_STREAM_AS_FD , (void * )& connection -> info -> fd , 1 )) {
890886				php_error_docref (NULL , E_WARNING , "Could not cast stream" );
891- 				zend_string_release_ex (resource_key , /* persistent */  false);
892- 				zval_ptr_dtor (return_value );
893- 				RETURN_FALSE ;
887+ 				goto fail ;
894888#ifdef  F_SETFL 
895889			} else  if  (modenr  ==  DBA_CREAT ) {
896890				int  flags  =  fcntl (connection -> info -> fd , F_GETFL );
@@ -924,9 +918,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
924918				php_error_docref (NULL , E_WARNING , "Driver initialization failed for handler: %s" , hptr -> name );
925919			}
926920		}
927- 		zend_string_release_ex (resource_key , /* persistent */  false);
928- 		zval_ptr_dtor (return_value );
929- 		RETURN_FALSE ;
921+ 		goto fail ;
930922	}
931923
932924	connection -> info -> hnd  =  hptr ;
@@ -935,13 +927,22 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
935927		if  (zend_register_persistent_resource_ex (connection -> hash , connection -> info , le_pdb ) ==  NULL ) {
936928			php_error_docref (NULL , E_WARNING , "Could not register persistent resource" );
937929			zend_string_release_ex (resource_key , /* persistent */  false);
930+ 			dba_close_connection (connection );
938931			zval_ptr_dtor (return_value );
939932			RETURN_FALSE ;
940933		}
941934	}
942935
943936	zend_hash_add_new (& DBA_G (connections ), connection -> hash , return_value );
944937	zend_string_release_ex (resource_key , /* persistent */  false);
938+ 	return ;
939+ fail :
940+ 	zend_string_release_ex (resource_key , /* persistent */  false);
941+ 	zend_string_release_ex (connection -> hash , persistent );
942+ 	dba_close_info (connection -> info );
943+ 	connection -> info  =  NULL ;
944+ 	zval_ptr_dtor (return_value );
945+ 	RETURN_FALSE ;
945946}
946947/* }}} */ 
947948
0 commit comments