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

Commit01b01a7

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 parentf5cee41 commit01b01a7

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
@@ -395,48 +395,54 @@ WaitLatchOrSocket(Latch *latch, int wakeEvents, pgsocket sock,
395395
WaitEventevent;
396396
WaitEventSet*set=CreateWaitEventSet(CurrentMemoryContext,3);
397397

398-
if (wakeEvents&WL_TIMEOUT)
399-
Assert(timeout >=0);
400-
else
401-
timeout=-1;
398+
PG_TRY();
399+
{
400+
if (wakeEvents&WL_TIMEOUT)
401+
Assert(timeout >=0);
402+
else
403+
timeout=-1;
402404

403-
if (wakeEvents&WL_LATCH_SET)
404-
AddWaitEventToSet(set,WL_LATCH_SET,PGINVALID_SOCKET,
405-
latch,NULL);
405+
if (wakeEvents&WL_LATCH_SET)
406+
AddWaitEventToSet(set,WL_LATCH_SET,PGINVALID_SOCKET,
407+
latch,NULL);
406408

407-
/* Postmaster-managed callers must handle postmaster death somehow. */
408-
Assert(!IsUnderPostmaster||
409-
(wakeEvents&WL_EXIT_ON_PM_DEATH)||
410-
(wakeEvents&WL_POSTMASTER_DEATH));
409+
/* Postmaster-managed callers must handle postmaster death somehow. */
410+
Assert(!IsUnderPostmaster||
411+
(wakeEvents&WL_EXIT_ON_PM_DEATH)||
412+
(wakeEvents&WL_POSTMASTER_DEATH));
411413

412-
if ((wakeEvents&WL_POSTMASTER_DEATH)&&IsUnderPostmaster)
413-
AddWaitEventToSet(set,WL_POSTMASTER_DEATH,PGINVALID_SOCKET,
414-
NULL,NULL);
414+
if ((wakeEvents&WL_POSTMASTER_DEATH)&&IsUnderPostmaster)
415+
AddWaitEventToSet(set,WL_POSTMASTER_DEATH,PGINVALID_SOCKET,
416+
NULL,NULL);
415417

416-
if ((wakeEvents&WL_EXIT_ON_PM_DEATH)&&IsUnderPostmaster)
417-
AddWaitEventToSet(set,WL_EXIT_ON_PM_DEATH,PGINVALID_SOCKET,
418-
NULL,NULL);
418+
if ((wakeEvents&WL_EXIT_ON_PM_DEATH)&&IsUnderPostmaster)
419+
AddWaitEventToSet(set,WL_EXIT_ON_PM_DEATH,PGINVALID_SOCKET,
420+
NULL,NULL);
419421

420-
if (wakeEvents&WL_SOCKET_MASK)
421-
{
422-
intev;
422+
if (wakeEvents&WL_SOCKET_MASK)
423+
{
424+
intev;
423425

424-
ev=wakeEvents&WL_SOCKET_MASK;
425-
AddWaitEventToSet(set,ev,sock,NULL,NULL);
426-
}
426+
ev=wakeEvents&WL_SOCKET_MASK;
427+
AddWaitEventToSet(set,ev,sock,NULL,NULL);
428+
}
427429

428-
rc=WaitEventSetWait(set,timeout,&event,1,wait_event_info);
430+
rc=WaitEventSetWait(set,timeout,&event,1,wait_event_info);
429431

430-
if (rc==0)
431-
ret |=WL_TIMEOUT;
432-
else
432+
if (rc==0)
433+
ret |=WL_TIMEOUT;
434+
else
435+
{
436+
ret |=event.events& (WL_LATCH_SET |
437+
WL_POSTMASTER_DEATH |
438+
WL_SOCKET_MASK);
439+
}
440+
}
441+
PG_FINALLY();
433442
{
434-
ret |=event.events& (WL_LATCH_SET |
435-
WL_POSTMASTER_DEATH |
436-
WL_SOCKET_MASK);
443+
FreeWaitEventSet(set);
437444
}
438-
439-
FreeWaitEventSet(set);
445+
PG_END_TRY();
440446

441447
returnret;
442448
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp