New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pqxx::connection_base does not have a virtual DTOR #57
Comments
That is correct. There are no virtual functions in this class, so there is no need for a virtual destructor. |
I was able to do: |
True.
So, the rule of thumb: if you intend pointers usage like @kalman5 mentioned, or you have any virtual methods in child classes, you must always make destructor virtual in the very base class of hierarchy. |
Fact is that most of methods take a pqxx:connection_base for reference so it seems valid to have pointers to pqxx::connection_base around, but deleting a connection trough a pqxx::connection_base pointer leaks the connection. I'd say fine that pqxx::connection_base doesn't have a virtual table but then in his destructor we need to call the close(). |
I suppose I always assumed that whoever created the connection would also ensure that it was closed, with the full type information at hand. If nothing else, the advent of move semantics may have upset that calculation. Something else that puzzles me now, decades later, is that I don't see why connectionpolicy should have a vtable. |
You can remove the vtable entirely from connectionpolicy, indeed you are using a specialization of it inside basic_connection trough a pointer to the base class neither trough a reference. |
Ah, no — I think some design considerations are starting to come back to me... The It's all pretty brittle, but ISTM changing this without breaking things could require some invasive surgery, and not necessarily take us to a better design. Perhaps the best thing I can do right now is document it properly! |
Not released yet, but in If you don't mind I'll close this ticket now, so it's off the to-do list. Please try the latest development versions! |
It looks like the pqxx::connection_base doesn't not have the virtual DTOR
The text was updated successfully, but these errors were encountered: