Merge pull request #2822 from citusdata/fix_find_worker_node

Copy WorkerNode before returning in FindWorkerNode
pull/2830/head
Marco Slot 2019-07-05 18:13:11 +02:00 committed by GitHub
commit 8617838fd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -764,7 +764,7 @@ get_shard_id_for_distribution_column(PG_FUNCTION_ARGS)
WorkerNode *
FindWorkerNode(char *nodeName, int32 nodePort)
{
WorkerNode *workerNode = NULL;
WorkerNode *cachedWorkerNode = NULL;
HTAB *workerNodeHash = GetWorkerNodeHash();
bool handleFound = false;
void *hashKey = NULL;
@ -774,10 +774,16 @@ FindWorkerNode(char *nodeName, int32 nodePort)
searchedNode->workerPort = nodePort;
hashKey = (void *) searchedNode;
workerNode = (WorkerNode *) hash_search(workerNodeHash, hashKey,
HASH_FIND, &handleFound);
cachedWorkerNode = (WorkerNode *) hash_search(workerNodeHash, hashKey, HASH_FIND,
&handleFound);
if (handleFound)
{
WorkerNode *workerNode = (WorkerNode *) palloc(sizeof(WorkerNode));
memcpy(workerNode, cachedWorkerNode, sizeof(WorkerNode));
return workerNode;
}
return workerNode;
return NULL;
}