pgsql: Fix two ancient memory-leak bugs in relcache.c.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix two ancient memory-leak bugs in relcache.c.
Date: 2014-05-18 20:52:15
Message-ID: E1Wm847-0006yT-SK@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix two ancient memory-leak bugs in relcache.c.

RelationCacheInsert() ignored the possibility that hash_search(HASH_ENTER)
might find a hashtable entry already present for the same OID. However,
that can in fact occur during recursive relcache load scenarios. When it
did happen, we overwrote the pointer to the pre-existing Relation, causing
a session-lifespan leakage of that entire structure. As far as is known,
the pre-existing Relation would always have reference count zero by the
time we arrive back at the outer insertion, so add code that deletes the
pre-existing Relation if so. If by some chance its refcount is positive,
elog a WARNING and allow the pre-existing Relation to be leaked as before.

Also, AttrDefaultFetch() was sloppy about leaking the cstring form of the
pg_attrdef.adbin value it's copying into the relcache structure. This is
only a query-lifespan leakage, and normally not very significant, but it
adds up during CLOBBER_CACHE testing.

These bugs are of very ancient vintage, but I'll refrain from back-patching
since there's no evidence that these leaks amount to anything in ordinary
usage.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/078b2ed291c758e7125d72c3a235f128d40a232b

Modified Files
--------------
src/backend/utils/cache/relcache.c | 69 +++++++++++++++++++++++++-----------
1 file changed, 48 insertions(+), 21 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2014-05-18 22:17:58 pgsql: Ooops, I broke initdb with that last patch.
Previous Message Tom Lane 2014-05-17 22:29:56 pgsql: Make fallback implementation of pg_memory_barrier() work.