From a62435607252f7286023fe38e39f57e6581790c9 Mon Sep 17 00:00:00 2001 From: Itagaki Takahiro Date: Wed, 9 Jun 2010 00:56:02 +0000 Subject: [PATCH] Fix connection leak in dblink when dblink_connect() or dblink_connect_u() end with "duplicate connection name" errors. Backported to release 7.4. --- contrib/dblink/dblink.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index 88f8130fd7..b9ba4f9482 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -8,7 +8,7 @@ * Darko Prenosil * Shridhar Daithankar * - * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.92 2010/06/03 09:38:33 itagaki Exp $ + * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.93 2010/06/09 00:56:02 itagaki Exp $ * Copyright (c) 2001-2010, PostgreSQL Global Development Group * ALL RIGHTS RESERVED; * @@ -2237,9 +2237,14 @@ createNewConnection(const char *name, remoteConn *rconn) HASH_ENTER, &found); if (found) + { + PQfinish(rconn->conn); + pfree(rconn); + ereport(ERROR, (errcode(ERRCODE_DUPLICATE_OBJECT), errmsg("duplicate connection name"))); + } hentry->rconn = rconn; strlcpy(hentry->name, name, sizeof(hentry->name)); -- 2.40.0