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

Commitb82dca2

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 parentd85db0a commitb82dca2

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
@@ -529,48 +529,54 @@ WaitLatchOrSocket(Latch *latch, int wakeEvents, pgsocket sock,
529529
WaitEventevent;
530530
WaitEventSet*set=CreateWaitEventSet(CurrentMemoryContext,3);
531531

532-
if (wakeEvents&WL_TIMEOUT)
533-
Assert(timeout >=0);
534-
else
535-
timeout=-1;
532+
PG_TRY();
533+
{
534+
if (wakeEvents&WL_TIMEOUT)
535+
Assert(timeout >=0);
536+
else
537+
timeout=-1;
536538

537-
if (wakeEvents&WL_LATCH_SET)
538-
AddWaitEventToSet(set,WL_LATCH_SET,PGINVALID_SOCKET,
539-
latch,NULL);
539+
if (wakeEvents&WL_LATCH_SET)
540+
AddWaitEventToSet(set,WL_LATCH_SET,PGINVALID_SOCKET,
541+
latch,NULL);
540542

541-
/* Postmaster-managed callers must handle postmaster death somehow. */
542-
Assert(!IsUnderPostmaster||
543-
(wakeEvents&WL_EXIT_ON_PM_DEATH)||
544-
(wakeEvents&WL_POSTMASTER_DEATH));
543+
/* Postmaster-managed callers must handle postmaster death somehow. */
544+
Assert(!IsUnderPostmaster||
545+
(wakeEvents&WL_EXIT_ON_PM_DEATH)||
546+
(wakeEvents&WL_POSTMASTER_DEATH));
545547

546-
if ((wakeEvents&WL_POSTMASTER_DEATH)&&IsUnderPostmaster)
547-
AddWaitEventToSet(set,WL_POSTMASTER_DEATH,PGINVALID_SOCKET,
548-
NULL,NULL);
548+
if ((wakeEvents&WL_POSTMASTER_DEATH)&&IsUnderPostmaster)
549+
AddWaitEventToSet(set,WL_POSTMASTER_DEATH,PGINVALID_SOCKET,
550+
NULL,NULL);
549551

550-
if ((wakeEvents&WL_EXIT_ON_PM_DEATH)&&IsUnderPostmaster)
551-
AddWaitEventToSet(set,WL_EXIT_ON_PM_DEATH,PGINVALID_SOCKET,
552-
NULL,NULL);
552+
if ((wakeEvents&WL_EXIT_ON_PM_DEATH)&&IsUnderPostmaster)
553+
AddWaitEventToSet(set,WL_EXIT_ON_PM_DEATH,PGINVALID_SOCKET,
554+
NULL,NULL);
553555

554-
if (wakeEvents&WL_SOCKET_MASK)
555-
{
556-
intev;
556+
if (wakeEvents&WL_SOCKET_MASK)
557+
{
558+
intev;
557559

558-
ev=wakeEvents&WL_SOCKET_MASK;
559-
AddWaitEventToSet(set,ev,sock,NULL,NULL);
560-
}
560+
ev=wakeEvents&WL_SOCKET_MASK;
561+
AddWaitEventToSet(set,ev,sock,NULL,NULL);
562+
}
561563

562-
rc=WaitEventSetWait(set,timeout,&event,1,wait_event_info);
564+
rc=WaitEventSetWait(set,timeout,&event,1,wait_event_info);
563565

564-
if (rc==0)
565-
ret |=WL_TIMEOUT;
566-
else
566+
if (rc==0)
567+
ret |=WL_TIMEOUT;
568+
else
569+
{
570+
ret |=event.events& (WL_LATCH_SET |
571+
WL_POSTMASTER_DEATH |
572+
WL_SOCKET_MASK);
573+
}
574+
}
575+
PG_FINALLY();
567576
{
568-
ret |=event.events& (WL_LATCH_SET |
569-
WL_POSTMASTER_DEATH |
570-
WL_SOCKET_MASK);
577+
FreeWaitEventSet(set);
571578
}
572-
573-
FreeWaitEventSet(set);
579+
PG_END_TRY();
574580

575581
returnret;
576582
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp