Re: Fixing memory leaks in postgres_fdw
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Etsuro Fujita <etsuro.fujita@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2025-05-25T23:59:00Z
Lists: pgsql-hackers
Attachments
- v3-0001-Fix-memory-leakage-in-postgres_fdw-s-DirectModify.patch (text/x-diff) patch v3-0001
- v3-0002-Silence-leakage-complaint-about-postgres_fdw-s-In.patch (text/x-diff) patch v3-0002
I wrote: > Here is an attempt at making a bulletproof fix by having all backend > users of libpq go through a wrapper layer that provides the memory > context callback. Perhaps this is more code churn than we want to > accept; I'm not sure. I thought about avoiding most of the niggling > code changes by adding > #define PGresult BEPGresult > #define PQclear BEPQclear > #define PQresultStatus BEPQresultStatus > and so forth at the bottom of the new header file, but I'm afraid > that would create a lot of confusion. I tried that, and it leads to such a less-messy patch that I think we should probably do it this way, confusion or no. One argument that can be made in favor is that we don't really want random notational differences between frontend and backend code that's doing the same thing. Also, I'd been struggling with the assumption that we should palloc the wrapper object before calling PQgetResult; there doesn't seem to be any nice way to make that transparent to callers. I realized that we can make it simple as long as we're willing to assume that allocating with MCXT_ALLOC_NO_OOM can't throw an error. But we assume that in other usages too. Hence, v3 attached. The 0002 patch is still the same as before. regards, tom lane
Commits
-
Silence leakage complaint about postgres_fdw's InitPgFdwOptions.
- 0f9d4d7c12dc 19 (unreleased) landed
-
Run pgindent on the changes of the previous patch.
- 73873805fb36 19 (unreleased) landed
-
Reap the benefits of not having to avoid leaking PGresults.
- 80aa9848befc 19 (unreleased) landed
-
Create infrastructure to reliably prevent leakage of PGresults.
- 7d8f59577924 19 (unreleased) landed
-
Fix memory leakage in postgres_fdw's DirectModify code path.
- 9339c85afc91 17.6 landed
- 4a07c096132c 14.19 landed
- 3c31594f55cd 15.14 landed
- 2b92dc4eeb51 16.10 landed
- 271cb7eaa7c8 13.22 landed
- 232d8caeaaa6 18.0 landed
-
Avoid resource leaks when a dblink connection fails.
- e7d3d4ed412e 13.22 landed
- e20b3256ae46 17.6 landed
- 8eef55db13fe 16.10 landed
- 470273da0ff7 18.0 landed
- 2cd2222ca5f4 14.19 landed
- 09c9ae8f6d3a 15.14 landed