Skip site navigation (1) Skip section navigation (2)

pgsql: Fix memory leaks in record_out() and record_send().

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix memory leaks in record_out() and record_send().
Date: 2012-11-13 19:46:20
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-committers
Fix memory leaks in record_out() and record_send().

record_out() leaks memory: it fails to free the strings returned by the
per-column output functions, and also is careless about detoasted values.
This results in a query-lifespan memory leakage when returning composite
values to the client, because printtup() runs the output functions in the
query-lifespan memory context.  Fix it to handle these issues the same way
printtup() does.  Also fix a similar leakage in record_send().

(At some point we might want to try to run output functions in
shorter-lived memory contexts, so that we don't need a zero-leakage policy
for them.  But that would be a significantly more invasive patch, which
doesn't seem like material for back-patching.)

In passing, use appendStringInfoCharMacro instead of appendStringInfoChar
in the innermost data-copying loop of record_out, to try to shave a few
cycles from this function's runtime.

Per trouble report from Carlos Henrique Reimer.  Back-patch to all
supported versions.



Modified Files
src/backend/utils/adt/rowtypes.c |   52 +++++++++++++++++++++++++++++--------
1 files changed, 40 insertions(+), 12 deletions(-)

pgsql-committers by date

Next:From: Bruce MomjianDate: 2012-11-14 02:08:16
Subject: pgsql: Adjust find_status for newer Linux 'nm' output format.
Previous:From: Simon RiggsDate: 2012-11-13 19:14:45
Subject: pgsql: Skip searching for subxact locks at commit.

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group