From 8f68671ad22f175a0b232d40695cef7fe6fb77d3 Mon Sep 17 00:00:00 2001 From: Arseny Sher Date: Thu, 2 Apr 2020 21:00:26 +0300 Subject: [PATCH] [PGPRO-3725] zero out garbage in append_rel_array if we allocate it. Since 1d9056f563f3 (who uses AppendRelInfo* existence as a mark this rel is child) in 11.7 this led to (known) random segfaults. --- src/hooks.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hooks.c b/src/hooks.c index 12c053b2..ca1db9be 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -498,9 +498,13 @@ pathman_rel_pathlist_hook(PlannerInfo *root, irange_len * sizeof(RangeTblEntry *)); #if PG_VERSION_NUM >= 110000 - /* Make sure append_rel_array is wide enough */ + /* + * Make sure append_rel_array is wide enough; if it hasn't been + * allocated previously, care to zero out [0; current_len) part. + */ if (root->append_rel_array == NULL) - root->append_rel_array = (AppendRelInfo **) palloc0(0); + root->append_rel_array = (AppendRelInfo **) + palloc0(current_len * sizeof(AppendRelInfo *)); root->append_rel_array = (AppendRelInfo **) repalloc(root->append_rel_array, new_len * sizeof(AppendRelInfo *));