Fix a couple of contrib/dblink bugs.
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.

royc1/gpdb,janebeckman/gpdb,royc1/gpdb,cjcjameson/gpdb,cjcjameson/gpdb,xinzweb/gpdb,0x0FFF/gpdb,50wu/gpdb,yuanzhao/gpdb,50wu/gpdb,kaknikhil/gpdb,edespino/gpdb,rvs/gpdb,lintzc/gpdb,zaksoup/gpdb,rvs/gpdb,lintzc/gpdb,chrishajas/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,royc1/gpdb,greenplum-db/gpdb,yuanzhao/gpdb,cjcjameson/gpdb,Chibin/gpdb,ahachete/gpdb,ashwinstar/gpdb,greenplum-db/gpdb,CraigHarris/gpdb,rvs/gpdb,zaksoup/gpdb,jmcatamney/gpdb,rvs/gpdb,greenplum-db/gpdb,kaknikhil/gpdb,janebeckman/gpdb,kaknikhil/gpdb,Quikling/gpdb,CraigHarris/gpdb,xinzweb/gpdb,ashwinstar/gpdb,adam8157/gpdb,xinzweb/gpdb,edespino/gpdb,Quikling/gpdb,lisakowen/gpdb,0x0FFF/gpdb,yuanzhao/gpdb,lisakowen/gpdb,xinzweb/gpdb,zaksoup/gpdb,Chibin/gpdb,lintzc/gpdb,0x0FFF/gpdb,cjcjameson/gpdb,ahachete/gpdb,Quikling/gpdb,Chibin/gpdb,edespino/gpdb,CraigHarris/gpdb,adam8157/gpdb,Chibin/gpdb,royc1/gpdb,CraigHarris/gpdb,CraigHarris/gpdb,janebeckman/gpdb,royc1/gpdb,zaksoup/gpdb,cjcjameson/gpdb,xuegang/gpdb,kaknikhil/gpdb,kaknikhil/gpdb,50wu/gpdb,janebeckman/gpdb,cjcjameson/gpdb,lisakowen/gpdb,zaksoup/gpdb,edespino/gpdb,kaknikhil/gpdb,jmcatamney/gpdb,xinzweb/gpdb,jmcatamney/gpdb,edespino/gpdb,chrishajas/gpdb,0x0FFF/gpdb,lisakowen/gpdb,50wu/gpdb,0x0FFF/gpdb,Chibin/gpdb,lintzc/gpdb,xinzweb/gpdb,cjcjameson/gpdb,yuanzhao/gpdb,kaknikhil/gpdb,zaksoup/gpdb,greenplum-db/gpdb,Quikling/gpdb,ashwinstar/gpdb,ahachete/gpdb,yuanzhao/gpdb,lisakowen/gpdb,chrishajas/gpdb,edespino/gpdb,kaknikhil/gpdb,ashwinstar/gpdb,adam8157/gpdb,edespino/gpdb,greenplum-db/gpdb,ahachete/gpdb,jmcatamney/gpdb,Quikling/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,janebeckman/gpdb,lintzc/gpdb,chrishajas/gpdb,janebeckman/gpdb,ahachete/gpdb,xuegang/gpdb,lisakowen/gpdb,Chibin/gpdb,rvs/gpdb,adam8157/gpdb,edespino/gpdb,rvs/gpdb,kaknikhil/gpdb,yuanzhao/gpdb,Chibin/gpdb,Quikling/gpdb,lisakowen/gpdb,jmcatamney/gpdb,Chibin/gpdb,50wu/gpdb,xinzweb/gpdb,ahachete/gpdb,cjcjameson/gpdb,CraigHarris/gpdb,rvs/gpdb,ahachete/gpdb,chrishajas/gpdb,cjcjameson/gpdb,lintzc/gpdb,xuegang/gpdb,CraigHarris/gpdb,chrishajas/gpdb,xuegang/gpdb,50wu/gpdb,xuegang/gpdb,jmcatamney/gpdb,chrishajas/gpdb,jmcatamney/gpdb,xuegang/gpdb,Chibin/gpdb,edespino/gpdb,kaknikhil/gpdb,xuegang/gpdb,Chibin/gpdb,zaksoup/gpdb,Quikling/gpdb,rvs/gpdb,xuegang/gpdb,adam8157/gpdb,0x0FFF/gpdb,lintzc/gpdb,adam8157/gpdb,CraigHarris/gpdb,Quikling/gpdb,adam8157/gpdb,lintzc/gpdb,Quikling/gpdb,chrishajas/gpdb,0x0FFF/gpdb,lisakowen/gpdb,edespino/gpdb,ahachete/gpdb,zaksoup/gpdb,lintzc/gpdb,royc1/gpdb,janebeckman/gpdb,Quikling/gpdb,royc1/gpdb,CraigHarris/gpdb,yuanzhao/gpdb,cjcjameson/gpdb,janebeckman/gpdb,jmcatamney/gpdb,xinzweb/gpdb,yuanzhao/gpdb,50wu/gpdb,rvs/gpdb,xuegang/gpdb,rvs/gpdb,janebeckman/gpdb,greenplum-db/gpdb,royc1/gpdb,adam8157/gpdb,50wu/gpdb,yuanzhao/gpdb,janebeckman/gpdb,yuanzhao/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,0x0FFF/gpdb