postgres.git / summary / log / commit / refs
commit ed71d7356e3b394f579db87782a41e3d5dfb99ad
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Mon Apr 06 12:46:03 2026 +0000
Fix memory leaks introduced by commit 283e823f9dcb
When freeing pending_shmem_requests we should also free the ->options.
Author: Aleksander Alekseev <aleksander@tigerdata.com>
Discussion: https://www.postgresql.org/message-id/CAJ7c6TN9tp8MTc0WXM0zfSWqjfBqU8gpe+o5KqHB1-cQ7409Kw@mail.gmail.com
src/backend/storage/ipc/shmem.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
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;
[parent: 2670a0fcc6a5]