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
dsa_pointer control;
tree = (RT_RADIX_TREE *) palloc0(sizeof(RT_RADIX_TREE));
+ tree->context = CurrentMemoryContext;
/* Find the control object in shared memory */
control = 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;
}
RT_DETACH(RT_RADIX_TREE * tree)
{
Assert(tree->ctl->magic == RT_RADIX_TREE_MAGIC);
+ MemoryContextDelete(tree->iter_context);
pfree(tree);
}