Skip to content

Commit e5af3c8

Browse files
committed
Fixed GH-18247: dba_popen() memory leak on invalid path.
and a handful more error code paths.
1 parent 90fd764 commit e5af3c8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ext/dba/dba.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
865865
if (!connection->info->lock.fp) {
866866
/* stream operation already wrote an error message */
867867
efree(resource_key);
868+
zend_string_release_ex(connection->hash, persistent);
869+
dba_close_info(connection->info);
870+
connection->info = NULL;
868871
zval_ptr_dtor(return_value);
869872
RETURN_FALSE;
870873
}
@@ -886,6 +889,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
886889
if (!connection->info->fp) {
887890
/* stream operation already wrote an error message */
888891
efree(resource_key);
892+
zend_string_release_ex(connection->hash, persistent);
893+
dba_close_info(connection->info);
894+
connection->info = NULL;
889895
zval_ptr_dtor(return_value);
890896
RETURN_FALSE;
891897
}
@@ -896,6 +902,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
896902
if (SUCCESS != php_stream_cast(connection->info->fp, PHP_STREAM_AS_FD, (void*)&connection->info->fd, 1)) {
897903
php_error_docref(NULL, E_WARNING, "Could not cast stream");
898904
efree(resource_key);
905+
zend_string_release_ex(connection->hash, persistent);
906+
dba_close_info(connection->info);
907+
connection->info = NULL;
899908
zval_ptr_dtor(return_value);
900909
RETURN_FALSE;
901910
#ifdef F_SETFL
@@ -932,6 +941,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
932941
}
933942
}
934943
efree(resource_key);
944+
zend_string_release_ex(connection->hash, persistent);
945+
dba_close_info(connection->info);
946+
connection->info = NULL;
935947
zval_ptr_dtor(return_value);
936948
RETURN_FALSE;
937949
}
@@ -942,6 +954,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
942954
if (zend_register_persistent_resource(resource_key, resource_key_len, connection->info, le_pdb) == NULL) {
943955
php_error_docref(NULL, E_WARNING, "Could not register persistent resource");
944956
efree(resource_key);
957+
dba_close_connection(connection);
945958
zval_ptr_dtor(return_value);
946959
RETURN_FALSE;
947960
}

0 commit comments

Comments
 (0)