postgresql/contrib/postgres_fdw
Tom Lane a3bed62d44 Fix low-probability leaks of PGresult objects in the backend.
We had three occurrences of essentially the same coding pattern
wherein we tried to retrieve a query result from a libpq connection
without blocking.  In the case where PQconsumeInput failed (typically
indicating a lost connection), all three loops simply gave up and
returned, forgetting to clear any previously-collected PGresult
object.  Since those are malloc'd not palloc'd, the oversight results
in a process-lifespan memory leak.

One instance, in libpqwalreceiver, is of little significance because
the walreceiver process would just quit anyway if its connection fails.
But we might as well fix it.

The other two instances, in postgres_fdw, are somewhat more worrisome
because at least in principle the scenario could be repeated, allowing
the amount of memory leaked to build up to something worth worrying
about.  Moreover, in these cases the loops contain CHECK_FOR_INTERRUPTS
calls, as well as other calls that could potentially elog(ERROR),
providing another way to exit without having cleared the PGresult.
Here we need to add PG_TRY logic similar to what exists in quite a
few other places in postgres_fdw.

Coverity noted the libpqwalreceiver bug; I found the other two cases
by checking all calls of PQconsumeInput.

Back-patch to all supported versions as appropriate (9.2 lacks
postgres_fdw, so this is really quite unexciting for that branch).

Discussion: https://postgr.es/m/22620.1497486981@sss.pgh.pa.us
2017-06-15 15:03:52 -04:00
..
expected psql: Use more consistent capitalization of some output headings 2017-06-13 14:41:14 -04:00
sql postgres_fdw: Fix join push down with extensions 2017-04-24 22:50:07 -04:00
.gitignore
connection.c Fix low-probability leaks of PGresult objects in the backend. 2017-06-15 15:03:52 -04:00
deparse.c Post-PG 10 beta1 pgindent run 2017-05-17 16:31:56 -04:00
Makefile Allow postgres_fdw to ship extension funcs/operators for remote execution. 2015-11-03 18:42:18 -05:00
option.c Move some things from builtins.h to new header files 2017-01-20 20:29:53 -05:00
postgres_fdw--1.0.sql
postgres_fdw.c Post-PG 10 beta1 pgindent run 2017-05-17 16:31:56 -04:00
postgres_fdw.control
postgres_fdw.h Post-PG 10 beta1 pgindent run 2017-05-17 16:31:56 -04:00
shippable.c Update copyright via script for 2017 2017-01-03 13:48:53 -05:00