Hi Heikki, > Introduce a new mechanism for registering shared memory areas > > [...]
This commit introduced a memory leak which Valgrind is very much upset about. ShmemRequestStructWithOpts() allocates a copy of `options` in TopMemoryContext and passes it to ShmemRequestInternal(). It appends it to pending_shmem_requests as request->options. Later in ShmemInitRequested() when the list is freed `->options` leak. There are similar issues in ShmemAttachRequested() and CallShmemCallbacksAfterStartup() which free pending_shmem_requests without freeing `->options`. I propose to fix it as attached. -- Best regards, Aleksander Alekseev
From 5edf1d194c545e7eb59364c50d26f0c087fef3a2 Mon Sep 17 00:00:00 2001 From: Aleksander Alekseev <[email protected]> Date: Mon, 6 Apr 2026 14:27:09 +0300 Subject: [PATCH v1] Fix memory leaks introduced by commit 283e823f9dcb When freeing pending_shmem_requests we should also free ->options pointers. Author: Aleksander Alekseev <[email protected]> Discussion: https://postgr.es/m/E1w9WsZ-00399s-08%40gemulon.postgresql.org --- src/backend/storage/ipc/shmem.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index 92c96257588..79adb4f6c61 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -435,6 +435,7 @@ ShmemInitRequested(void) foreach_ptr(ShmemRequest, request, pending_shmem_requests) { InitShmemIndexEntry(request); + pfree(request->options); } list_free_deep(pending_shmem_requests); pending_shmem_requests = NIL; @@ -477,6 +478,7 @@ ShmemAttachRequested(void) foreach_ptr(ShmemRequest, request, pending_shmem_requests) { AttachShmemIndexEntry(request, false); + pfree(request->options); } list_free_deep(pending_shmem_requests); pending_shmem_requests = NIL; @@ -947,6 +949,8 @@ CallShmemCallbacksAfterStartup(const ShmemCallbacks *callbacks) AttachShmemIndexEntry(request, false); else InitShmemIndexEntry(request); + + pfree(request->options); } list_free_deep(pending_shmem_requests); pending_shmem_requests = NIL; -- 2.43.0
