diff options
author | Heikki Linnakangas | 2023-11-08 23:33:14 +0000 |
---|---|---|
committer | Heikki Linnakangas | 2023-11-08 23:33:14 +0000 |
commit | 8f4a1ab471e6a258881e3d7f5883705714cde7e1 (patch) | |
tree | 1199c23ac5424a12afbc16c8f34d79bdc81379c9 | |
parent | 322f55bdbd018bf18a0c5605c7bc592c625dc263 (diff) |
Fix bug in the new ResourceOwner implementation.
When the hash table is in use, ResoureOwnerSort() moves any elements
from the small fixed-size array to the hash table, and sorts it. When
the hash table is not in use, it sorts the elements in the small
fixed-size array directly. However, ResourceOwnerSort() and
ResourceOwnerReleaseAll() had different idea on when the hash table is
in use: ResourceOwnerSort() checked owner->nhash != 0, and
ResourceOwnerReleaseAll() checked owner->hash != NULL. If the hash
table was allocated but was currently empty, you hit an assertion
failure.
Reported-by: Alexander Lakhin <[email protected]>
Discussion: https://www.postgresql.org/message-id/[email protected]
-rw-r--r-- | src/backend/utils/resowner/resowner.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/backend/utils/resowner/resowner.c b/src/backend/utils/resowner/resowner.c index eecb3ade3d7..f096f3df20a 100644 --- a/src/backend/utils/resowner/resowner.c +++ b/src/backend/utils/resowner/resowner.c @@ -349,10 +349,13 @@ ResourceOwnerReleaseAll(ResourceOwner owner, ResourceReleasePhase phase, ResourceElem *items; uint32 nitems; - /* ResourceOwnerSort must've been called already */ + /* + * ResourceOwnerSort must've been called already. All the resources are + * either in the array or the hash. + */ Assert(owner->releasing); Assert(owner->sorted); - if (!owner->hash) + if (owner->nhash == 0) { items = owner->arr; nitems = owner->narr; @@ -393,7 +396,7 @@ ResourceOwnerReleaseAll(ResourceOwner owner, ResourceReleasePhase phase, kind->ReleaseResource(value); nitems--; } - if (!owner->hash) + if (owner->nhash == 0) owner->narr = nitems; else owner->nhash = nitems; |