Skip to content

6.4.0: Object lifetime bug fixed

Compare
Choose a tag to compare
@jtv jtv released this 19 Mar 23:43
· 1667 commits to master since this release

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:

  1. The application receives a result object from a connection.
  2. It destroys the connection, but keeps the result.
  3. And, it continues using the result.
  4. 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.