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);