aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMasahiko Sawada <msawada@postgresql.org>2025-02-06 11:35:51 -0800
committerMasahiko Sawada <msawada@postgresql.org>2025-02-06 11:35:51 -0800
commit9af2b3435844526ff503f2509c5246749b9c48b0 (patch)
treedddab4cf2a0f98ce7bb0cda5b959a416a5cc883d /src
parent32770ea03247bc42b38ccc53b84711e0c13d1498 (diff)
downloadpostgresql-9af2b3435844526ff503f2509c5246749b9c48b0.tar.gz
postgresql-9af2b3435844526ff503f2509c5246749b9c48b0.zip
radixtree: Fix crash when non-creator begins iteration over shared tree.
Previously, if a backend that attached to a shared tree attempted to start iteration, it resulted in a crash. This commit resolves the issue by ensuring iter_context is created in RT_ATTACH(). This fix applies only to v17, where radixtree.h was introduced. In the master branch, this issue was separately resolved by 960013f2a1, which eliminated the iter_context entirely. Reviewed-by: John Naylor Discussion: https://postgr.es/m/CAD21AoBB2U47V=F+wQRB1bERov_of5=BOZGaybjaV8FLQyqG3Q@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/include/lib/radixtree.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/include/lib/radixtree.h b/src/include/lib/radixtree.h
index 1301f3fee44..4cbadf4f5ec 100644
--- a/src/include/lib/radixtree.h
+++ b/src/include/lib/radixtree.h
@@ -1902,6 +1902,7 @@ RT_ATTACH(dsa_area *dsa, RT_HANDLE handle)
dsa_pointer control;
tree = (RT_RADIX_TREE *) palloc0(sizeof(RT_RADIX_TREE));
+ tree->context = CurrentMemoryContext;
/* Find the control object in shared memory */
control = handle;
@@ -1910,6 +1911,14 @@ RT_ATTACH(dsa_area *dsa, RT_HANDLE handle)
tree->ctl = (RT_RADIX_TREE_CONTROL *) dsa_get_address(dsa, control);
Assert(tree->ctl->magic == RT_RADIX_TREE_MAGIC);
+ /*
+ * Create the iteration context so that the attached backend also can
+ * begin the iteration.
+ */
+ tree->iter_context = AllocSetContextCreate(CurrentMemoryContext,
+ RT_STR(RT_PREFIX) "_radix_tree iter context",
+ ALLOCSET_SMALL_SIZES);
+
return tree;
}
@@ -1917,6 +1926,7 @@ RT_SCOPE void
RT_DETACH(RT_RADIX_TREE * tree)
{
Assert(tree->ctl->magic == RT_RADIX_TREE_MAGIC);
+ MemoryContextDelete(tree->iter_context);
pfree(tree);
}