} else {
COPY_CLIENT_ERROR(*conn->error_info, result->stored_data->error_info);
stmt->result->m.free_result_contents(stmt->result);
- mnd_efree(stmt->result);
+ mnd_pefree(stmt->result, stmt->result->persistent);
stmt->result = NULL;
stmt->state = MYSQLND_STMT_PREPARED;
}
if (FAIL == (ret = PACKET_READ(fields_eof, stmt->conn))) {
if (stmt->result) {
stmt->result->m.free_result_contents(stmt->result);
- mnd_efree(stmt->result);
+ mnd_pefree(stmt->result, stmt->result->persistent);
memset(stmt, 0, sizeof(MYSQLND_STMT_DATA));
stmt->state = MYSQLND_STMT_INITTED;
}
--- /dev/null
+--TEST--
+Bug #74376 (Invalid free of persistent results on error/connection loss)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded');
+require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
+require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
+MySQLPDOTest::skip();
+?>
+--FILE--
+<?php
+require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
+
+$attr = getenv('PDOTEST_ATTR');
+$attr = $attr ? unserialize($attr) : [];
+$attr[PDO::ATTR_PERSISTENT] = true;
+$attr[PDO::ATTR_EMULATE_PREPARES] = false;
+
+putenv('PDOTEST_ATTR=' . serialize($attr));
+
+$db = MySQLPDOTest::factory();
+$stmt = $db->query("select (select 1 union select 2)");
+
+print "ok";
+?>
+--EXPECTF--
+ok