Skip to content

Commit

Permalink
894: Fix error-reporting crash in non-blocking connection.
Browse files Browse the repository at this point in the history
Fixes: #894

If construction of a non-blocking `connection` failed for a reason
_other_ than an out-of-memory error, then reporting of the error
would fail.  This happened because the error-reporting code tried to
read the error message _after it had already cleared the connection
pointer._  This means reading deallocated memory.
  • Loading branch information
jtv committed Oct 5, 2024
1 parent 793fbfe commit da3a611
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Don't call`/bin/true`; macOS doesn't have it. Just call `true`. (#885)
- Deprecate `exec_prepared()`; just use `exec()` with a `pqxx::prepped`.
- Deprecate `exec1()` etc. Use `result::expect_rows()` etc.
- Fix error-reporting crash in non-blocking connection constructor. (#894)
7.9.2
- Fix CMake documentation install. (#848)
- More CMake build fix. (#869)
Expand Down
3 changes: 2 additions & 1 deletion src/connection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ pqxx::connection::connection(
throw std::bad_alloc{};
if (status() == CONNECTION_BAD)
{
std::string const msg{PQerrorMessage(m_conn)};
PQfinish(m_conn);
m_conn = nullptr;
throw pqxx::broken_connection{PQerrorMessage(m_conn)};
throw pqxx::broken_connection{msg};
}
}

Expand Down

0 comments on commit da3a611

Please sign in to comment.