From de32b7bbadb9aafc4e3b13d05111f46f37fca107 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Mon, 3 Oct 2016 13:05:05 -0700 Subject: [PATCH] Don't create hash-table of zero size in TaskHashCreate(). hash_create(), called by TaskHashCreate(), doesn't work correctly for a zero sized hash table. This triggers valgrind errors, and could potentially cause crashes even without valgring. This currently happens for Jobs with 0 tasks. These probably should be optimized away before reaching TaskHashCreate(), but that's a bigger change. --- .../distributed/executor/multi_task_tracker_executor.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/backend/distributed/executor/multi_task_tracker_executor.c b/src/backend/distributed/executor/multi_task_tracker_executor.c index e08657e98..8bdcdacd3 100644 --- a/src/backend/distributed/executor/multi_task_tracker_executor.c +++ b/src/backend/distributed/executor/multi_task_tracker_executor.c @@ -519,6 +519,15 @@ TaskHashCreate(uint32 taskHashSize) int hashFlags = 0; HTAB *taskHash = NULL; + /* + * Can't create a hashtable of size 0. Normally that shouldn't happen, but + * shard pruning currently can lead to this (Job with 0 Tasks). See #833. + */ + if (taskHashSize == 0) + { + taskHashSize = 2; + } + memset(&info, 0, sizeof(info)); info.keysize = sizeof(TaskMapKey); info.entrysize = sizeof(TaskMapEntry);