xref: /PHP-8.1/ext/mysqli/tests/bug69899.phpt (revision b5a14e6c)
1--TEST--
2Bug #69899: Segfault on stmt close after free_result with mysqlnd.
3--DESCRIPTION--
4The segfault happens only if the database connection was already closed and
5free_result is called on a prepared statement followed by closing that
6statement. This is due to mysqlnd_stmt::free_result (mysqlnd_ps.c) which
7unconditionally sets the connection of the statement to ready, despite the fact
8that it might already be closed.
9--EXTENSIONS--
10mysqli
11--SKIPIF--
12<?php
13require_once __DIR__ . '/skipifconnectfailure.inc';
14require_once __DIR__ . '/connect.inc';
15if (!$IS_MYSQLND) {
16    die('skip mysqlnd only');
17}
18?>
19--FILE--
20<?php
21
22require_once __DIR__ . '/connect.inc';
23
24mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
25
26$mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket);
27$stmt   = $mysqli->prepare('SELECT 1');
28
29var_dump(
30    $mysqli->close(),
31    $stmt->free_result(),
32    $stmt->close()
33);
34
35?>
36--EXPECT--
37bool(true)
38NULL
39bool(true)
40