pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix memory leak in TRUNCATE decoding
Date: Mon, 03 Sep 2018 00:31:41 +0000
Message-ID: <E1fwcmL-0007Ku-IA@gemulon.postgresql.org> (raw)

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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4ddd8f5f55a0a1967fc787e42182745ca1e3a995

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(-)



view thread (2+ messages)

Message-ID: <E1fwcmL-0007Ku-IA@gemulon.postgresql.org>
Permalink:  ../E1fwcmL-0007Ku-IA@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1fwcmL-0007Ku-IA@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tomas.vondra@postgresql.org
  Subject: Re: pgsql: Fix memory leak in TRUNCATE decoding
  In-Reply-To: <E1fwcmL-0007Ku-IA@gemulon.postgresql.org>
  References: <E1fwcmL-0007Ku-IA@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox