Re: [PATCH] Fix memory leak of primary_sysid in walreceiver

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: DaeMyung Kang <charsyam@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2026-04-27T00:36:55Z
Lists: pgsql-hackers
On Mon, Apr 27, 2026 at 02:01:30AM +0900, DaeMyung Kang wrote:
> The attached patch adds a pfree(primary_sysid) right after the
> comparison.

My first impression was that it does not matter because I was under
the impression that this code path is only reached once, but that's
not the case: a WAL receiver could stay around waiting for
instructions before retrying a connection.

I doubt that this is worth bothering for in the back branches, as it
just means a small leak each time we switch to a new TLI repeatedly,
something that would matter mostly for a cascading standby where we
don't want to change the connection point (a SIGHUP'd primary_conninto
enforces a WAL receiver shutdown).  Let's clean up on HEAD, though.
--
Michael

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix some memory leaks in the WAL receiver

  2. Refactor libpqwalreceiver