Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb714bc4

Browse files
author
Etsuro Fujita
committed
Fix WaitEventSet resource leak in WaitLatchOrSocket().
This function would have the same issue we solved in commit501cfd0:If an error is thrown after calling CreateWaitEventSet(), the filedescriptor (on epoll- or kqueue-based systems) or handles (on Windows)that the WaitEventSet contains are leaked.Like that commit, use PG_TRY-PG_FINALLY (PG_TRY-PG_CATCH in v12) to makesure the WaitEventSet is freed properly.Back-patch to all supported versions, but as we do not have this issuein HEAD (cf. commit50c67c2), no need to apply this patch to it.Discussion:https://postgr.es/m/CAPmGK16MqdDoD8oatp8SQWaEa4vS3nfQqDN_Sj9YRuu5J3Lj9g%40mail.gmail.com
1 parentdc5824a commitb714bc4

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

‎src/backend/storage/ipc/latch.c

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -526,48 +526,54 @@ WaitLatchOrSocket(Latch *latch, int wakeEvents, pgsocket sock,
526526
WaitEventevent;
527527
WaitEventSet*set=CreateWaitEventSet(CurrentMemoryContext,3);
528528

529-
if (wakeEvents&WL_TIMEOUT)
530-
Assert(timeout >=0);
531-
else
532-
timeout=-1;
529+
PG_TRY();
530+
{
531+
if (wakeEvents&WL_TIMEOUT)
532+
Assert(timeout >=0);
533+
else
534+
timeout=-1;
533535

534-
if (wakeEvents&WL_LATCH_SET)
535-
AddWaitEventToSet(set,WL_LATCH_SET,PGINVALID_SOCKET,
536-
latch,NULL);
536+
if (wakeEvents&WL_LATCH_SET)
537+
AddWaitEventToSet(set,WL_LATCH_SET,PGINVALID_SOCKET,
538+
latch,NULL);
537539

538-
/* Postmaster-managed callers must handle postmaster death somehow. */
539-
Assert(!IsUnderPostmaster||
540-
(wakeEvents&WL_EXIT_ON_PM_DEATH)||
541-
(wakeEvents&WL_POSTMASTER_DEATH));
540+
/* Postmaster-managed callers must handle postmaster death somehow. */
541+
Assert(!IsUnderPostmaster||
542+
(wakeEvents&WL_EXIT_ON_PM_DEATH)||
543+
(wakeEvents&WL_POSTMASTER_DEATH));
542544

543-
if ((wakeEvents&WL_POSTMASTER_DEATH)&&IsUnderPostmaster)
544-
AddWaitEventToSet(set,WL_POSTMASTER_DEATH,PGINVALID_SOCKET,
545-
NULL,NULL);
545+
if ((wakeEvents&WL_POSTMASTER_DEATH)&&IsUnderPostmaster)
546+
AddWaitEventToSet(set,WL_POSTMASTER_DEATH,PGINVALID_SOCKET,
547+
NULL,NULL);
546548

547-
if ((wakeEvents&WL_EXIT_ON_PM_DEATH)&&IsUnderPostmaster)
548-
AddWaitEventToSet(set,WL_EXIT_ON_PM_DEATH,PGINVALID_SOCKET,
549-
NULL,NULL);
549+
if ((wakeEvents&WL_EXIT_ON_PM_DEATH)&&IsUnderPostmaster)
550+
AddWaitEventToSet(set,WL_EXIT_ON_PM_DEATH,PGINVALID_SOCKET,
551+
NULL,NULL);
550552

551-
if (wakeEvents&WL_SOCKET_MASK)
552-
{
553-
intev;
553+
if (wakeEvents&WL_SOCKET_MASK)
554+
{
555+
intev;
554556

555-
ev=wakeEvents&WL_SOCKET_MASK;
556-
AddWaitEventToSet(set,ev,sock,NULL,NULL);
557-
}
557+
ev=wakeEvents&WL_SOCKET_MASK;
558+
AddWaitEventToSet(set,ev,sock,NULL,NULL);
559+
}
558560

559-
rc=WaitEventSetWait(set,timeout,&event,1,wait_event_info);
561+
rc=WaitEventSetWait(set,timeout,&event,1,wait_event_info);
560562

561-
if (rc==0)
562-
ret |=WL_TIMEOUT;
563-
else
563+
if (rc==0)
564+
ret |=WL_TIMEOUT;
565+
else
566+
{
567+
ret |=event.events& (WL_LATCH_SET |
568+
WL_POSTMASTER_DEATH |
569+
WL_SOCKET_MASK);
570+
}
571+
}
572+
PG_FINALLY();
564573
{
565-
ret |=event.events& (WL_LATCH_SET |
566-
WL_POSTMASTER_DEATH |
567-
WL_SOCKET_MASK);
574+
FreeWaitEventSet(set);
568575
}
569-
570-
FreeWaitEventSet(set);
576+
PG_END_TRY();
571577

572578
returnret;
573579
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp