From 48552bfffed9d2a033a08abeb6be743af1a79ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Thu, 7 Nov 2019 22:34:53 +0000 Subject: [PATCH] Call DestReceiver rDestroy before it goes out of scope CitusCopyDestReceiverDestroy: call hash_destroy on shardStateHash & connectionStateHash --- .../commands/create_distributed_table.c | 1 + src/backend/distributed/commands/multi_copy.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/backend/distributed/commands/create_distributed_table.c b/src/backend/distributed/commands/create_distributed_table.c index e4593aca3..d879ecde8 100644 --- a/src/backend/distributed/commands/create_distributed_table.c +++ b/src/backend/distributed/commands/create_distributed_table.c @@ -1343,6 +1343,7 @@ CopyLocalDataIntoShards(Oid distributedRelationId) /* finish writing into the shards */ copyDest->rShutdown(copyDest); + copyDest->rDestroy(copyDest); /* free memory and close the relation */ ExecDropSingleTupleTableSlot(slot); diff --git a/src/backend/distributed/commands/multi_copy.c b/src/backend/distributed/commands/multi_copy.c index d708f2f69..c857ad417 100644 --- a/src/backend/distributed/commands/multi_copy.c +++ b/src/backend/distributed/commands/multi_copy.c @@ -598,6 +598,7 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag) /* finish the COPY commands */ dest->rShutdown(dest); + dest->rDestroy(dest); ExecDropSingleTupleTableSlot(tupleTableSlot); FreeExecutorState(executorState); @@ -2692,6 +2693,9 @@ ShutdownCopyConnectionState(CopyConnectionState *connectionState, } +/* + * CitusCopyDestReceiverDestroy frees the DestReceiver + */ static void CitusCopyDestReceiverDestroy(DestReceiver *destReceiver) { @@ -2712,6 +2716,16 @@ CitusCopyDestReceiverDestroy(DestReceiver *destReceiver) pfree(copyDest->columnCoercionPaths); } + if (copyDest->shardStateHash) + { + hash_destroy(copyDest->shardStateHash); + } + + if (copyDest->connectionStateHash) + { + hash_destroy(copyDest->connectionStateHash); + } + pfree(copyDest); }