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.
release-5.2
Andres Freund 2016-10-03 13:05:05 -07:00
parent 94dc5768fe
commit 3df78ebd4a
1 changed files with 9 additions and 0 deletions

View File

@ -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);