pgsql: In libpq, free any partial query result before collecting a serv

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: In libpq, free any partial query result before collecting a serv
Date: 2018-04-13 16:54:05
Message-ID: E1f71xd-0004tv-0g@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

In libpq, free any partial query result before collecting a server error.

We'd throw away the partial result anyway after parsing the error message.
Throwing it away beforehand costs nothing and reduces the risk of
out-of-memory failure. Also, at least in systems that behave like
glibc/Linux, if the partial result was very large then the error PGresult
would get allocated at high heap addresses, preventing the heap storage
used by the partial result from being released to the OS until the error
PGresult is freed.

In psql >= 9.6, we hold onto the error PGresult until another error is
received (for \errverbose), so that this behavior causes a seeming
memory leak to persist for awhile, as in a recent complaint from
Darafei Praliaskouski. This is a potential performance regression from
older versions, justifying back-patching at least that far. But similar
behavior may occur in other client applications, so it seems worth just
back-patching to all supported branches.

Discussion: https://postgr.es/m/CAC8Q8tJ=7cOkPePyAbJE_Pf691t8nDFhJp0KZxHvnq_uicfyVg@mail.gmail.com

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2278e94ae9410716209487ad929d2eae24da0b47

Modified Files
--------------
src/interfaces/libpq/fe-protocol2.c | 10 +++++++++-
src/interfaces/libpq/fe-protocol3.c | 10 +++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2018-04-13 17:49:58 pgsql: Improve regression test coverage for src/backend/tsearch/spell.c
Previous Message Tom Lane 2018-04-13 16:54:04 pgsql: In libpq, free any partial query result before collecting a serv