@@ -864,9 +864,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
864864 }
865865 if (!connection -> info -> lock .fp ) {
866866 /* stream operation already wrote an error message */
867- efree (resource_key );
868- zval_ptr_dtor (return_value );
869- RETURN_FALSE ;
867+ goto fail ;
870868 }
871869 if (!error && !php_stream_supports_lock (connection -> info -> lock .fp )) {
872870 error = "Stream does not support locking" ;
@@ -885,19 +883,15 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
885883 }
886884 if (!connection -> info -> fp ) {
887885 /* stream operation already wrote an error message */
888- efree (resource_key );
889- zval_ptr_dtor (return_value );
890- RETURN_FALSE ;
886+ goto fail ;
891887 }
892888 if (hptr -> flags & (DBA_NO_APPEND |DBA_CAST_AS_FD )) {
893889 /* Needed because some systems do not allow to write to the original
894890 * file contents with O_APPEND being set.
895891 */
896892 if (SUCCESS != php_stream_cast (connection -> info -> fp , PHP_STREAM_AS_FD , (void * )& connection -> info -> fd , 1 )) {
897893 php_error_docref (NULL , E_WARNING , "Could not cast stream" );
898- efree (resource_key );
899- zval_ptr_dtor (return_value );
900- RETURN_FALSE ;
894+ goto fail ;
901895#ifdef F_SETFL
902896 } else if (modenr == DBA_CREAT ) {
903897 int flags = fcntl (connection -> info -> fd , F_GETFL );
@@ -931,9 +925,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
931925 php_error_docref (NULL , E_WARNING , "Driver initialization failed for handler: %s" , hptr -> name );
932926 }
933927 }
934- efree (resource_key );
935- zval_ptr_dtor (return_value );
936- RETURN_FALSE ;
928+ goto fail ;
937929 }
938930
939931 connection -> info -> hnd = hptr ;
@@ -942,13 +934,22 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
942934 if (zend_register_persistent_resource (resource_key , resource_key_len , connection -> info , le_pdb ) == NULL ) {
943935 php_error_docref (NULL , E_WARNING , "Could not register persistent resource" );
944936 efree (resource_key );
937+ dba_close_connection (connection );
945938 zval_ptr_dtor (return_value );
946939 RETURN_FALSE ;
947940 }
948941 }
949942
950943 zend_hash_add_new (& DBA_G (connections ), connection -> hash , return_value );
951944 efree (resource_key );
945+ return ;
946+ fail :
947+ efree (resource_key );
948+ zend_string_release_ex (connection -> hash , persistent );
949+ dba_close_info (connection -> info );
950+ connection -> info = NULL ;
951+ zval_ptr_dtor (return_value );
952+ RETURN_FALSE ;
952953}
953954/* }}} */
954955
0 commit comments