Skip to content

Commit 95936c7

Browse files
committed
Fix memory leak on DSM slot exhaustion.
If we attempt to create a DSM segment when no slots are available, we should return the memory to the operating system. Previously we did that if the DSM_CREATE_NULL_IF_MAXSEGMENTS flag was passed in, but we didn't do it if an error was raised. Repair. Back-patch to 9.4, where DSM segments arrived. Author: Thomas Munro Reviewed-by: Robert Haas Reported-by: Julian Backes Discussion: https://postgr.es/m/CA%2BhUKGKAAoEw-R4om0d2YM4eqT1eGEi6%3DQot-3ceDR-SLiWVDw%40mail.gmail.com
1 parent f521ef0 commit 95936c7

File tree

1 file changed

+9
-0
lines changed
  • src/backend/storage/ipc

1 file changed

+9
-0
lines changed

src/backend/storage/ipc/dsm.c

+9
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,18 @@ dsm_create(Size size)
496496

497497
/* Verify that we can support an additional mapping. */
498498
if (nitems >= dsm_control->maxitems)
499+
{
500+
LWLockRelease(DynamicSharedMemoryControlLock);
501+
dsm_impl_op(DSM_OP_DESTROY, seg->handle, 0, &seg->impl_private,
502+
&seg->mapped_address, &seg->mapped_size, WARNING);
503+
if (seg->resowner != NULL)
504+
ResourceOwnerForgetDSM(seg->resowner, seg);
505+
dlist_delete(&seg->node);
506+
pfree(seg);
499507
ereport(ERROR,
500508
(errcode(ERRCODE_INSUFFICIENT_RESOURCES),
501509
errmsg("too many dynamic shared memory segments")));
510+
}
502511

503512
/* Enter the handle into a new array slot. */
504513
dsm_control->item[nitems].handle = seg->handle;

0 commit comments

Comments
 (0)