From: Heikki Linnakangas Date: Mon, 6 Apr 2026 12:46:03 +0000 (+0300) Subject: Fix memory leaks introduced by commit 283e823f9dcb X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed71d7356e3b394f579db87782a41e3d5dfb99ad;p=thirdparty%2Fpostgresql.git Fix memory leaks introduced by commit 283e823f9dcb When freeing pending_shmem_requests we should also free the ->options. Author: Aleksander Alekseev Discussion: https://www.postgresql.org/message-id/CAJ7c6TN9tp8MTc0WXM0zfSWqjfBqU8gpe+o5KqHB1-cQ7409Kw@mail.gmail.com --- diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index 92c96257588..1ebffe5a32a 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -327,9 +327,10 @@ ShmemRequestStructWithOpts(const ShmemStructOpts *options) /* * Internal workhorse of ShmemRequestStruct() and ShmemRequestHash(). * - * Note: 'options' must live until the init/attach callbacks have been called. - * Unlike in the public ShmemRequestStruct() and ShmemRequestHash() functions, - * 'options' is *not* copied. This allows ShmemRequestHash() to pass a + * Note: Unlike in the public ShmemRequestStruct() and ShmemRequestHash() + * functions, 'options' is *not* copied. It must be allocated in + * TopMemoryContext by the caller, and will be freed after the init/attach + * callbacks have been called. This allows ShmemRequestHash() to pass a * pointer to the extended ShmemHashOpts struct instead. */ void @@ -435,6 +436,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 +479,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 +950,8 @@ CallShmemCallbacksAfterStartup(const ShmemCallbacks *callbacks) AttachShmemIndexEntry(request, false); else InitShmemIndexEntry(request); + + pfree(request->options); } list_free_deep(pending_shmem_requests); pending_shmem_requests = NIL;