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

Commit0341d4b

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 parent5e9d8be commit0341d4b

File tree

1 file changed

+39
-30
lines changed

1 file changed

+39
-30
lines changed

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

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -374,46 +374,55 @@ WaitLatchOrSocket(Latch *latch, int wakeEvents, pgsocket sock,
374374
WaitEventevent;
375375
WaitEventSet*set=CreateWaitEventSet(CurrentMemoryContext,3);
376376

377-
if (wakeEvents&WL_TIMEOUT)
378-
Assert(timeout >=0);
379-
else
380-
timeout=-1;
377+
PG_TRY();
378+
{
379+
if (wakeEvents&WL_TIMEOUT)
380+
Assert(timeout >=0);
381+
else
382+
timeout=-1;
381383

382-
if (wakeEvents&WL_LATCH_SET)
383-
AddWaitEventToSet(set,WL_LATCH_SET,PGINVALID_SOCKET,
384-
latch,NULL);
384+
if (wakeEvents&WL_LATCH_SET)
385+
AddWaitEventToSet(set,WL_LATCH_SET,PGINVALID_SOCKET,
386+
latch,NULL);
385387

386-
/* Postmaster-managed callers must handle postmaster death somehow. */
387-
Assert(!IsUnderPostmaster||
388-
(wakeEvents&WL_EXIT_ON_PM_DEATH)||
389-
(wakeEvents&WL_POSTMASTER_DEATH));
388+
/* Postmaster-managed callers must handle postmaster death somehow. */
389+
Assert(!IsUnderPostmaster||
390+
(wakeEvents&WL_EXIT_ON_PM_DEATH)||
391+
(wakeEvents&WL_POSTMASTER_DEATH));
390392

391-
if ((wakeEvents&WL_POSTMASTER_DEATH)&&IsUnderPostmaster)
392-
AddWaitEventToSet(set,WL_POSTMASTER_DEATH,PGINVALID_SOCKET,
393-
NULL,NULL);
393+
if ((wakeEvents&WL_POSTMASTER_DEATH)&&IsUnderPostmaster)
394+
AddWaitEventToSet(set,WL_POSTMASTER_DEATH,PGINVALID_SOCKET,
395+
NULL,NULL);
394396

395-
if ((wakeEvents&WL_EXIT_ON_PM_DEATH)&&IsUnderPostmaster)
396-
AddWaitEventToSet(set,WL_EXIT_ON_PM_DEATH,PGINVALID_SOCKET,
397-
NULL,NULL);
397+
if ((wakeEvents&WL_EXIT_ON_PM_DEATH)&&IsUnderPostmaster)
398+
AddWaitEventToSet(set,WL_EXIT_ON_PM_DEATH,PGINVALID_SOCKET,
399+
NULL,NULL);
398400

399-
if (wakeEvents&WL_SOCKET_MASK)
400-
{
401-
intev;
401+
if (wakeEvents&WL_SOCKET_MASK)
402+
{
403+
intev;
402404

403-
ev=wakeEvents&WL_SOCKET_MASK;
404-
AddWaitEventToSet(set,ev,sock,NULL,NULL);
405-
}
405+
ev=wakeEvents&WL_SOCKET_MASK;
406+
AddWaitEventToSet(set,ev,sock,NULL,NULL);
407+
}
406408

407-
rc=WaitEventSetWait(set,timeout,&event,1,wait_event_info);
409+
rc=WaitEventSetWait(set,timeout,&event,1,wait_event_info);
408410

409-
if (rc==0)
410-
ret |=WL_TIMEOUT;
411-
else
411+
if (rc==0)
412+
ret |=WL_TIMEOUT;
413+
else
414+
{
415+
ret |=event.events& (WL_LATCH_SET |
416+
WL_POSTMASTER_DEATH |
417+
WL_SOCKET_MASK);
418+
}
419+
}
420+
PG_CATCH();
412421
{
413-
ret |=event.events& (WL_LATCH_SET |
414-
WL_POSTMASTER_DEATH |
415-
WL_SOCKET_MASK);
422+
FreeWaitEventSet(set);
423+
PG_RE_THROW();
416424
}
425+
PG_END_TRY();
417426

418427
FreeWaitEventSet(set);
419428

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp