| From: | DaeMyung Kang <charsyam(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Cc: | DaeMyung Kang <charsyam(at)gmail(dot)com> |
| Subject: | [PATCH] Fix memory leak of primary_sysid in walreceiver |
| Date: | 2026-04-26 17:01:30 |
| Message-ID: | 20260426170219.849330-1-charsyam@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi, Hackers,
In WalReceiverMain(), the outer streaming loop calls
walrcv_identify_system() once per iteration to verify the primary's
system identifier:
primary_sysid = walrcv_identify_system(wrconn, &primaryTLI);
...
if (strcmp(primary_sysid, standby_sysid) != 0)
ereport(ERROR, ...);
walrcv_identify_system() (libpqrcv_identify_system() in
libpqwalreceiver.c) returns a pstrdup()'d string, but the caller
never frees it. Each streaming restart therefore leaks the string.
The error path is unaffected because the surrounding memory context
is reset on ERROR.
The attached patch adds a pfree(primary_sysid) right after the
comparison.
This dates back to commit 78c8c814390 ("Refactor libpqwalreceiver",
2016), so it should be a back-patch candidate as well.
No new tests are added; the fix only releases resources and does not
change observable behavior. `make check` and the streaming replication
TAP test (src/test/recovery/t/001_stream_rep.pl) pass with the patch
applied.
Patch attached.
Regards,
DaeMyung Kang
| Attachment | Content-Type | Size |
|---|---|---|
| 0002-Fix-memory-leak-of-primary_sysid-in-walreceiver.patch | text/x-patch | 540 bytes |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Haas | 2026-04-26 17:09:32 | Re: Use log_newpage_range in HASH index build |
| Previous Message | Robert Haas | 2026-04-26 17:01:19 | Re: Pgbench: remove synchronous prepare |