]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix memory leaks introduced by commit 283e823f9dcb
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 6 Apr 2026 12:46:03 +0000 (15:46 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 6 Apr 2026 12:46:03 +0000 (15:46 +0300)
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

index 92c96257588f484d6faa720d48a4d581dd94a08e..1ebffe5a32a48bbd1723735cd4258aa3ff1136ca 100644 (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;