From 25673600d349561c92abc46b3ce30a330f6f8cfd Mon Sep 17 00:00:00 2001 From: Murat Tuncer Date: Fri, 28 Sep 2018 11:13:21 +0300 Subject: [PATCH] Fix memory leak in FinishRemoteTransactionPrepare --- .../transaction/remote_transaction.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/backend/distributed/transaction/remote_transaction.c b/src/backend/distributed/transaction/remote_transaction.c index f8eaf3d74..755400863 100644 --- a/src/backend/distributed/transaction/remote_transaction.c +++ b/src/backend/distributed/transaction/remote_transaction.c @@ -528,8 +528,22 @@ FinishRemoteTransactionPrepare(struct MultiConnection *connection) transaction->transactionState = REMOTE_TRANS_PREPARED; } - result = GetRemoteCommandResult(connection, raiseErrors); - Assert(!result); + PQclear(result); + + /* + * Try to consume results of PREPARE TRANSACTION command. If we don't + * succeed, rollback the transaction. Note that we've not committed on + * any node yet, and we're not sure about the state of the worker node. + * So rollbacking seems to be the safest action if the worker is + * in a state where it can actually rollback. + */ + if (!ClearResults(connection, raiseErrors)) + { + ereport(ERROR, (errmsg("failed to prepare transaction '%s' on host %s:%d", + transaction->preparedName, connection->hostname, + connection->port), + errhint("Try re-running the command."))); + } }