pgsql: Fix memory leak in TRUNCATE decoding

Поиск
Список
Период
Сортировка
От Tomas Vondra
Тема pgsql: Fix memory leak in TRUNCATE decoding
Дата
Msg-id E1fwcmA-0007KR-SC@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix memory leak in TRUNCATE decoding

When decoding a TRUNCATE record, the relids array was being allocated in
the main ReorderBuffer memory context, but not released with the change
resulting in a memory leak.

The array was also ignored when serializing/deserializing the change,
assuming all the information is stored in the change itself.  So when
spilling the change to disk, we've only we have serialized only the
pointer to the relids array.  Thanks to never releasing the array,
the pointer however remained valid even after loading the change back
to memory, preventing an actual crash.

This fixes both the memory leak and (de)serialization.  The relids array
is still allocated in the main ReorderBuffer memory context (none of the
existing ones seems like a good match, and adding an extra context seems
like an overkill).  The allocation is wrapped in a new ReorderBuffer API
functions, to keep the details within reorderbuffer.c, just like the
other ReorderBufferGet methods do.

Author: Tomas Vondra
Discussion: https://www.postgresql.org/message-id/flat/66175a41-9342-2845-652f-1bd4c3ee50aa%402ndquadrant.com
Backpatch: 11, where decoding of TRUNCATE was introduced

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/081cf78d12f17c97efc6199039bc83f059fffcf6

Modified Files
--------------
src/backend/replication/logical/decode.c        |  3 +-
src/backend/replication/logical/reorderbuffer.c | 69 ++++++++++++++++++++++++-
src/include/replication/reorderbuffer.h         |  3 ++
3 files changed, 73 insertions(+), 2 deletions(-)


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

Предыдущее
От: Michael Paquier
Дата:
Сообщение: pgsql: Fix initial sync of slot parent directory when restoring status
Следующее
От: Tomas Vondra
Дата:
Сообщение: pgsql: Fix memory leak in TRUNCATE decoding