Clear CurrentResourceOwner earlier in CommitTransaction.
authorHeikki Linnakangas <[email protected]>
Wed, 15 Nov 2023 09:34:35 +0000 (10:34 +0100)
committerHeikki Linnakangas <[email protected]>
Wed, 15 Nov 2023 10:03:49 +0000 (11:03 +0100)
Alexander reported a crash with repeated create + drop database, after
the ResourceOwner rewrite (commit b8bff07daa). That was fixed by the
previous commit, but it nevertheless seems like a good idea clear
CurrentResourceOwner earlier, because you're not supposed to use it
for anything after we start releasing it.

Reviewed-by: Alexander Lakhin
Discussion: https://www.postgresql.org/message-id/11b70743-c5f3-3910-8e5b-dd6c115ff829%40gmail.com

src/backend/access/transam/xact.c

index 74ce5f9491c2944c6dd6f5a3bc03a1191ed7043b..8fad8ffa1ebd4831fcef80575254e9765b8d4d34 100644 (file)
@@ -2309,6 +2309,7 @@ CommitTransaction(void)
        CallXactCallbacks(is_parallel_worker ? XACT_EVENT_PARALLEL_COMMIT
                                          : XACT_EVENT_COMMIT);
 
+       CurrentResourceOwner = NULL;
        ResourceOwnerRelease(TopTransactionResourceOwner,
                                                 RESOURCE_RELEASE_BEFORE_LOCKS,
                                                 true, true);
@@ -2374,7 +2375,6 @@ CommitTransaction(void)
        AtEOXact_LogicalRepWorkers(true);
        pgstat_report_xact_timestamp(0);
 
-       CurrentResourceOwner = NULL;
        ResourceOwnerDelete(TopTransactionResourceOwner);
        s->curTransactionOwner = NULL;
        CurTransactionResourceOwner = NULL;