pgsql: Fix worst memory leaks in tqueue.c.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix worst memory leaks in tqueue.c.
Дата
Msg-id E1bTHFT-0003qj-HL@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix worst memory leaks in tqueue.c.

TupleQueueReaderNext() leaks like a sieve if it has to do any tuple
disassembly/reconstruction.  While we could try to clean up its allocations
piecemeal, it seems like a better idea just to insist that it should be run
in a short-lived memory context, so that any transient space goes away
automatically.  I chose to have nodeGather.c switch into its existing
per-tuple context before the call, rather than inventing a separate
context inside tqueue.c.

This is sufficient to stop all leakage in the simple case I exhibited
earlier today (see link below), but it does not deal with leaks induced
in more complex cases by tqueue.c's insistence on using TopMemoryContext
for data that it's not actually trying hard to keep track of.  That issue
is intertwined with another major source of inefficiency, namely failure
to cache lookup results across calls, so it seems best to deal with it
separately.

In passing, improve some comments, and modify gather_readnext's method for
deciding when it's visited all the readers so that it's more obviously
correct.  (I'm not actually convinced that the previous code *is*
correct in the case of a reader deletion; it certainly seems fragile.)

Discussion: <32763.1469821037@sss.pgh.pa.us>

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/af33039317ddc4a0e38a02e2255c2bf453115fd2

Modified Files
--------------
src/backend/executor/nodeGather.c | 45 ++++++++++++++++++++++-----------------
src/backend/executor/tqueue.c     | 22 ++++++++++++-------
src/include/executor/tqueue.h     |  8 ++++---
3 files changed, 45 insertions(+), 30 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix tqueue.c's range-remapping code.
Следующее
От: Bruce Momjian
Дата:
Сообщение: pgsql: docs: properly capitalize and space kB, MB, GB, TB