diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2024-04-08 17:00:07 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2024-04-08 17:00:07 -0400 |
commit | f463de59d90c10f3d0daf2d5b132ca58e4111a08 (patch) | |
tree | d17294607a3ee43b7d81d1024a10ab238cfe1cb0 /src | |
parent | c21d4c416ad61b78cf450f11861bbafbdfb7eebc (diff) | |
download | postgresql-f463de59d90c10f3d0daf2d5b132ca58e4111a08.tar.gz postgresql-f463de59d90c10f3d0daf2d5b132ca58e4111a08.zip |
In psql, avoid leaking a PGresult after a query is cancelled.
After a query cancel, the tail end of ExecQueryAndProcessResults
took care to clear any not-yet-read PGresults; but it forgot about
the one it has already read. There would only be such a result
when handling a multi-command string made with "\;", so that you'd
have to cancel an earlier command in such a string to reach the
bug at all. Even then, there would only be leakage of a single
PGresult per cancel, so it's not surprising nobody noticed this.
But a leak is a leak.
Noted while re-reviewing 90f517821, but this is independent of that:
it dates to 7844c9918. Back-patch to v15 where that came in.
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/psql/common.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 69063a6f785..fe8e049c4c1 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -1812,6 +1812,8 @@ ExecQueryAndProcessResults(const char *query, if (cancel_pressed) { + /* drop this next result, as well as any others not yet read */ + ClearOrSaveResult(result); ClearOrSaveAllResults(); break; } |