diff --git a/ext/dba/dba.c b/ext/dba/dba.c index 7e8ef11b03d0f..1042226a46c50 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -860,11 +860,10 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) fcntl(info->fd, F_SETFL, flags & ~O_APPEND); #elif defined(PHP_WIN32) } else if (modenr == DBA_CREAT && need_creation && !restarted) { - zend_bool close_both; - - close_both = (info->fp != info->lock.fp); - php_stream_free(info->lock.fp, persistent ? PHP_STREAM_FREE_CLOSE_PERSISTENT : PHP_STREAM_FREE_CLOSE); - if (close_both) { + if (info->lock.fp != NULL) { + php_stream_free(info->lock.fp, persistent ? PHP_STREAM_FREE_CLOSE_PERSISTENT : PHP_STREAM_FREE_CLOSE); + } + if (info->fp != info->lock.fp) { php_stream_free(info->fp, persistent ? PHP_STREAM_FREE_CLOSE_PERSISTENT : PHP_STREAM_FREE_CLOSE); } info->fp = NULL; diff --git a/ext/dba/tests/gh9155.phpt b/ext/dba/tests/gh9155.phpt new file mode 100644 index 0000000000000..d8057517ec0c2 --- /dev/null +++ b/ext/dba/tests/gh9155.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug GH-9155 (dba_open("non-existing", "c-", "flatfile") segfaults) +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECTF-- +resource(%d) of type (dba)