Fix WaitEventSet resource leak in WaitLatchOrSocket().
authorEtsuro Fujita <[email protected]>
Thu, 11 Apr 2024 10:05:04 +0000 (19:05 +0900)
committerEtsuro Fujita <[email protected]>
Thu, 11 Apr 2024 10:05:04 +0000 (19:05 +0900)
commitb714bc40cf066dde745fcb78fde160788730a7be
tree6de218716168c64d95bfeec5ed7b648e5243ebd9
parentdc5824a06e979e1f4412849d63d166ca16d1f84d
Fix WaitEventSet resource leak in WaitLatchOrSocket().

This function would have the same issue we solved in commit 501cfd07d:
If an error is thrown after calling CreateWaitEventSet(), the file
descriptor (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 make
sure the WaitEventSet is freed properly.

Back-patch to all supported versions, but as we do not have this issue
in HEAD (cf. commit 50c67c201), no need to apply this patch to it.

Discussion: https://postgr.es/m/CAPmGK16MqdDoD8oatp8SQWaEa4vS3nfQqDN_Sj9YRuu5J3Lj9g%40mail.gmail.com
src/backend/storage/ipc/latch.c