Re: memory leak in GIN

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Cc: Jaime Casanova <jaime(dot)casanova(at)2ndquadrant(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Subject: Re: memory leak in GIN
Date: 2016-03-13 20:24:46
Message-ID: 19753.1457900686@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jeff Janes <jeff(dot)janes(at)gmail(dot)com> writes:
> I bisected it down to:

> d88976cfa1302e8dccdcbfe55e9e29faee8c0cdf is the first bad commit
> commit d88976cfa1302e8dccdcbfe55e9e29faee8c0cdf
> Author: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
> Date: Wed Feb 4 17:40:25 2015 +0200

> Use a separate memory context for GIN scan keys.

Yeah, I had come to the same conclusion. The leak comes from removing
this bit from ginFreeScanKeys():

- if (entry->list)
- pfree(entry->list);

Heikki evidently supposed that entry->list would be allocated in
the so->keyCtx, but as things stand, it is not: it gets allocated
in the query-lifespan context, so this change causes a leak of
potentially several kB per ginrescan cycle. And the test query
does about 120000 of those.

I think it would likely be a good thing to fix things so that that
assumption actually holds, but I'm not familiar enough with this code
to decide what's the best way to do that. (Basically, the question is
"how much of startScanEntry() ought to run with keyCtx as current memory
context?") As a short-term fix I plan to reinstall the above-cited pfree.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2016-03-13 21:18:46 Re: Recovery test failure for recovery_min_apply_delay on hamster
Previous Message Peter Geoghegan 2016-03-13 20:22:54 Re: amcheck (B-Tree integrity checking tool)