Fix a couple of contrib/dblink bugs.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 4 Apr 2012 00:43:20 +0000 (20:43 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 4 Apr 2012 00:43:20 +0000 (20:43 -0400)
commit8d2a5fb219aab954fe6642a2c1abdaa058ddeaef
tree302619739fa19e9e999daf77b2522889716dd2e8
parent99e2076bc73fe20c856986c50f4eafefa23edc38
Fix a couple of contrib/dblink bugs.

dblink_exec leaked temporary database connections if any error occurred
after connection setup, for example
SELECT dblink_exec('...connect string...', 'select 1/0');
Add a PG_TRY block to ensure PQfinish gets done when it is needed.
(dblink_record_internal is on the hairy edge of needing similar treatment,
but seems not to be actively broken at the moment.)

Also, in 9.0 and up, only one of the three functions using tuplestore
return mode was properly checking that the query context would allow
a tuplestore result.

Noted while reviewing dblink patch.  Back-patch to all supported branches.
contrib/dblink/dblink.c