postgresql/contrib/postgres_fdw
Heikki Linnakangas 501cfd07da Fix resource leak when a FDW's ForeignAsyncRequest function fails
If an error is thrown after calling CreateWaitEventSet(), the memory
of a WaitEventSet is free'd as it's allocated in the short-lived
memory context, but the file descriptor (on epoll- or kqueue-based
systems) or handles (on Windows) that it contains are leaked.

Use PG_TRY-FINALLY to ensure it gets freed. (On master, I will apply a
better fix, using ResourceOwners to track the WaitEventSet, but that's
not backpatchable.)

The added test doesn't check for leaking resources, so it passed even
before this commit. But at least it covers the code path.

In the passing, fix misleading comment on what the 'nevents' argument
to WaitEventSetWait means.

Report by Alexander Lakhin, analysis and suggestion for the fix by Tom
Lane. Fixes bug #17828. Backpatch to v14 where async execution was
introduced, but master gets a different fix.

Discussion: https://www.postgresql.org/message-id/17828-122da8cba23236be@postgresql.org
Discussion: https://www.postgresql.org/message-id/472235.1678387869@sss.pgh.pa.us
2023-11-23 13:30:13 +02:00
..
expected Fix resource leak when a FDW's ForeignAsyncRequest function fails 2023-11-23 13:30:13 +02:00
sql Fix resource leak when a FDW's ForeignAsyncRequest function fails 2023-11-23 13:30:13 +02:00
.gitignore Add postgres_fdw contrib module. 2013-02-21 05:27:16 -05:00
Makefile postgres_fdw: Add function to list cached connections to foreign servers. 2021-01-18 15:11:08 +09:00
connection.c rename "gss_accept_deleg" to "gss_accept_delegation". 2023-05-20 21:32:54 -04:00
deparse.c Fix various typos in code and tests 2023-02-09 14:43:53 +09:00
meson.build Update copyright for 2023 2023-01-02 15:00:37 -05:00
option.c Expand some more uses of "deleg" to "delegation" or "delegated". 2023-05-21 10:55:18 -04:00
postgres_fdw--1.0--1.1.sql postgres_fdw: Add functions to discard cached connections. 2021-01-26 15:35:54 +09:00
postgres_fdw--1.0.sql Add postgres_fdw contrib module. 2013-02-21 05:27:16 -05:00
postgres_fdw.c Fix filtering of "cloned" outer-join quals some more. 2023-05-25 10:28:33 -04:00
postgres_fdw.control postgres_fdw: Add function to list cached connections to foreign servers. 2021-01-18 15:11:08 +09:00
postgres_fdw.h Check relkind before using TABLESAMPLE in postgres_fdw 2023-01-07 14:39:33 +01:00
shippable.c Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00