Skip to content

Commit 6202e28

Browse files
committed
Fix leak of Pdo object if query() fails
Decref the DBH object when storing the errored query statement -- the DBH owns the stmt, so it will live long enough.
1 parent 32ab261 commit 6202e28

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

ext/pdo/pdo_dbh.c

+2
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,8 @@ static PHP_METHOD(PDO, query)
11141114
/* something broke */
11151115
dbh->query_stmt = stmt;
11161116
ZVAL_COPY_VALUE(&dbh->query_stmt_zval, return_value);
1117+
Z_DELREF(stmt->database_object_handle);
1118+
ZVAL_UNDEF(&stmt->database_object_handle);
11171119
PDO_HANDLE_STMT_ERR();
11181120
} else {
11191121
PDO_HANDLE_DBH_ERR();

ext/pdo/pdo_stmt.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ static int do_fetch_func_prepare(pdo_stmt_t *stmt) /* {{{ */
803803
}
804804
/* }}} */
805805

806-
static int do_fetch_opt_finish(pdo_stmt_t *stmt, int free_ctor_agrs) /* {{{ */
806+
static void do_fetch_opt_finish(pdo_stmt_t *stmt, int free_ctor_agrs) /* {{{ */
807807
{
808808
/* fci.size is used to check if it is valid */
809809
if (stmt->fetch.cls.fci.size && stmt->fetch.cls.fci.params) {
@@ -826,7 +826,6 @@ static int do_fetch_opt_finish(pdo_stmt_t *stmt, int free_ctor_agrs) /* {{{ */
826826
efree(stmt->fetch.func.values);
827827
stmt->fetch.func.values = NULL;
828828
}
829-
return 1;
830829
}
831830
/* }}} */
832831

0 commit comments

Comments
 (0)