6.4.0: Object lifetime bug fixed
This release addresses (but does not fully prevent) a subtle lifetime bug. Due to an unexpected subtlety in how libpq and libpqxx interact, an application would access invalid memory if the following things all happened together:
- The application receives a
result
object from a connection. - It destroys the connection, but keeps the
result
. - And, it continues using the
result
. - Then, it does something on the
result
which causes the underlying C driver, libpq, to issue an error or warning message.
Today's update can't prevent this, but it further limits the circumstances under which this can happen. Now, the bug will only happen if the connection has an errorhandler
registered on it at the time it produces the result
.
Documentation has been updated to mention this as a hazard of registering an error handler. If you need to register an errorhandler
on a connection, you will need to keep the connection object alive until you stop using the result
you got from that connection.