summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorJoe Conway <mail@joeconway.com>2017-03-11 13:33:22 -0800
committerJoe Conway <mail@joeconway.com>2017-03-11 13:33:22 -0800
commitf6cfc14e5ad3b8e5309615f8f7d15f55ba238f97 (patch)
tree2d349ac3d024813e81a360789511b3c3e54d6742 /contrib
parent0c0a95c2f83b4ed88ebb7f7759c22cd73e7b3cf3 (diff)
downloadpostgresql-f6cfc14e5ad3b8e5309615f8f7d15f55ba238f97.tar.gz
Fix ancient connection leak in dblink
When using unnamed connections with dblink, every time a new connection is made, the old one is leaked. Fix that. This has been an issue probably since dblink was first committed. Someone complained almost ten years ago, but apparently I decided not to pursue it at the time, and neither did anyone else, so it slipped between the cracks. Now that someone else has complained, fix in all supported branches. Discussion: (orig) https://postgr.es/m/flat/F680AB59-6D6F-4026-9599-1BE28880273D%40decibel.org#F680AB59-6D6F-4026-9599-1BE28880273D@decibel.org Discussion: (new) https://postgr.es/m/flat/0A3221C70F24FB45833433255569204D1F6ADF8C@G01JPEXMBYT05 Reported by: Jim Nasby and Takayuki Tsunakawa
Diffstat (limited to 'contrib')
-rw-r--r--contrib/dblink/dblink.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index ab378c9c3e..e86bb52e19 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -301,7 +301,11 @@ dblink_connect(PG_FUNCTION_ARGS)
createNewConnection(connname, rconn);
}
else
+ {
+ if (pconn->conn)
+ PQfinish(pconn->conn);
pconn->conn = conn;
+ }
PG_RETURN_TEXT_P(cstring_to_text("OK"));
}