Skip to content

Commit

Permalink
Fixed bug #67004
Browse files Browse the repository at this point in the history
Repeated execute() with native PS failed to release the previous
result set on libmysqlclient.

Move freeing the result set into a common location.
  • Loading branch information
nikic committed Dec 11, 2020
1 parent d6b4b82 commit ad8eb11
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ PHP NEWS
. Fixed bug #72368 (PdoStatement->execute() fails but does not throw an
exception). (Nikita)
. Fixed bug #62889 (LOAD DATA INFILE broken). (Nikita)
. Fixed bug #67004 (Executing PDOStatement::fetch() more than once prevents
releasing resultset). (Nikita)

- Phar:
. Fixed bug #73809 (Phar Zip parse crash - mmap fail). (cmb)
Expand Down
7 changes: 3 additions & 4 deletions ext/pdo_mysql/mysql_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo_stmt_t *stmt) /* {{{ */
PDO_DBG_RETURN(0);
}

pdo_mysql_free_result(S);
PDO_DBG_RETURN(pdo_mysql_stmt_after_execute_prepared(stmt));
}
/* }}} */
Expand All @@ -316,14 +315,14 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt) /* {{{ */
PDO_DBG_ENTER("pdo_mysql_stmt_execute");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);

/* ensure that we free any previous unfetched results */
pdo_mysql_free_result(S);
S->done = 0;

if (S->stmt) {
PDO_DBG_RETURN(pdo_mysql_stmt_execute_prepared(stmt));
}

/* ensure that we free any previous unfetched results */
pdo_mysql_free_result(S);

if (mysql_real_query(H->server, stmt->active_query_string, stmt->active_query_stringlen) != 0) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
Expand Down
34 changes: 34 additions & 0 deletions ext/pdo_mysql/tests/bug67004.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Bug #67004: Executing PDOStatement::fetch() more than once prevents releasing resultset
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
MySQLPDOTest::skip();
?>
--FILE--
<?php

require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
$dbh = MySQLPDOTest::factory();
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare("SELECT ?");

$stmt->execute(["foo"]);
var_dump($stmt->fetchColumn(0));

$stmt->execute(["bar"]);
var_dump($stmt->fetchColumn(0));

$stmt = $dbh->prepare("SELECT ?");
$stmt->execute(["baz"]);
var_dump($stmt->fetchColumn(0));

?>
--EXPECT--
string(3) "foo"
string(3) "bar"
string(3) "baz"

0 comments on commit ad8eb11

Please sign in to comment.