From f3d29dc5043c630beb55ed2640611358c6a9cf47 Mon Sep 17 00:00:00 2001 From: Guillaume Outters Date: Mon, 21 Oct 2024 00:39:14 +0200 Subject: [PATCH] ext/pdo_pgsql: factorize clearing of running_stmt GH-23065 fixed running_stmt being only conditionally cleared in pgsql_stmt_finish(), by clearing it from the different callers of pgsql_stmt_finish(); put the clearing back into pgsql_stmt_finish(), albeit this time with the right condition to have all callers satisfied. --- ext/pdo_pgsql/pgsql_statement.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index 2f0725534937..fe89afe9580d 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -195,6 +195,10 @@ static void pgsql_stmt_finish(pdo_pgsql_stmt *S, int fin_mode) S->is_prepared = false; } + + if ((fin_mode & (FIN_CLOSE|FIN_ABORT)) && H->running_stmt == S) { + H->running_stmt = NULL; + } } static int pgsql_stmt_dtor(pdo_stmt_t *stmt) @@ -204,10 +208,6 @@ static int pgsql_stmt_dtor(pdo_stmt_t *stmt) pgsql_stmt_finish(S, FIN_DISCARD|(server_obj_usable ? FIN_CLOSE|FIN_ABORT : 0)); - if (server_obj_usable && S->H->running_stmt == S) { - S->H->running_stmt = NULL; - } - if (S->stmt_name) { efree(S->stmt_name); S->stmt_name = NULL; @@ -273,7 +273,6 @@ static int pgsql_stmt_execute(pdo_stmt_t *stmt) * (maybe it will change with pipeline mode in libpq 14?) */ if (S->is_unbuffered && H->running_stmt) { pgsql_stmt_finish(H->running_stmt, FIN_CLOSE); - H->running_stmt = NULL; } /* ensure that we free any previous unfetched results */ pgsql_stmt_finish(S, 0);