Fix memory leaks introduced by commit 283e823f9d

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
This commit is contained in:
Heikki Linnakangas 2026-04-06 15:46:03 +03:00
parent 2670a0fcc6
commit ed71d7356e

View file

@ -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;