postgresql-interfaces/psqlodbc GitHub issues and pull requests (mirror)
help / color / mirror / Atom feedFrom: davecramer (@davecramer) <[email protected]>
To: postgresql-interfaces/psqlodbc <[email protected]>
Subject: Re: [postgresql-interfaces/psqlodbc] PR #188: Clear PGresults from per-query rollback
Date: Mon, 18 May 2026 19:12:38 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
The Bug
CC_internal_rollback() loops over PQgetResult() to drain all results from a multi-statement command (ROLLBACK TO
per_query_svp; RELEASE per_query_svp). Each iteration overwrites pgres with the next result, but never calls
PQclear() on the previous one — leaking it.
The Fix
default:
handle_pgres_error(self, pgres, __FUNCTION__, NULL, !ret);
}
+ PQclear(pgres);
+ pgres = NULL;
}
PQclear(pgres) inside the loop, immediately after the switch handles the result. pgres = NULL is defensive (prevents
double-free if the loop logic changes).
Assessment
Correct. This is the standard libpq pattern — every non-NULL PQgetResult() must be paired with a PQclear(). The fix
is placed after the switch statement so all cases (success, error) get cleared. PQclear(NULL) is a no-op per libpq
docs, so the NULL assignment is safe but not strictly necessary.
Verified by LSan. The PR description shows the leak was 432 bytes across 2 allocations (matching the two results
from the two-statement command), and the leak disappears after the fix.
No test added — the existing error-rollback-test exercises this path and passes. A dedicated leak test would require
LSan integration in CI, which is out of scope.
view thread (2+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: github://postgresql-interfaces/psqlodbc
Cc: [email protected], [email protected]
Subject: Re: [postgresql-interfaces/psqlodbc] PR #188: Clear PGresults from per-query rollback
In-Reply-To: <<[email protected]>>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox