From: Michael Paquier Date: Wed, 13 May 2026 06:39:44 +0000 (+0900) Subject: pg_stat_statements: Set PlannedStmt to NULL after nested utility execution X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66366217822e23a00251f6ba3743d8e5675fcfc2;p=thirdparty%2Fpostgresql.git pg_stat_statements: Set PlannedStmt to NULL after nested utility execution As mentioned in 8268e41aca23, pgss_ProcessUtility() may free the PlannedStmt after an internal ROLLBACK. This commit sets the PlannedStmt "pstmt" to NULL once it is no longer safe to rely on it, making bugs similar to the one fixed by the previous commit easier to detect. Suggested-by: Andres Freund Reviewed-by: Chao Li Discussion: https://postgr.es/m/0A9A8DAC-BC3C-4C7A-9504-2C6050405544@anarazel.de --- diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index a2d3ab770cc..92315627916 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -1175,6 +1175,7 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString, * For the same reason, we can't risk restoring pstmt->queryId to its * former value, which'd otherwise be a good idea. */ + pstmt = NULL; INSTR_TIME_SET_CURRENT(duration); INSTR_TIME_SUBTRACT(duration, start);