-
Notifications
You must be signed in to change notification settings - Fork 64
Memory leak if exception is thrown in connection constructor #31
Comments
By the way, credits: Valgrind detected this issue. |
Thanks! I believe I fixed this with the commit I just pushed to |
@rbock sorry but now I have 2 possible memory leaks and 1 definite memory leak report from valgrind (before I only had the 2 possible memory leaks). I'm running valgrind with these options: valgrind --leak-check=full --error-limit=no --show-leak-kinds=definite,indirect,possible \
--log-file=reports/valgrind.log \
--xml=yes --xml-file=reports/valgrind.xml I've atteched the XML report valgrind.xml.tar.gz (I don't know why but plain text report is empty...). |
I was able to generate the valgrid plain text log file (you can only generate plain text or XML, but not both at the same time...): valgrind.log I hope this could help you... thanks! 👍 |
I am sure this will help. Will look into it asap. Thanks for the reports!! |
Thanks! This helped indeed. A new version is on develop. I fixed a leak and added an raii struct for mysql_library_init/mysql_library_end. valgrind seems happy in the few tests I ran by now. |
@rbock I will try to test it asap. Thanks! |
@rbock now we have the 2 original possible memory leaks detected by Valgrind (valgrind.log). I think problem could fix it adding connection::connection(const std::shared_ptr<connection_config>& config)
: _handle(new detail::connection_handle_t(config))
{
if (mysql_set_character_set(_handle->mysql.get(), _handle->config->charset.c_str()))
{
delete _handle;
throw sqlpp::exception("MySQL error: can't set character set " + _handle->config->charset);
}
if (mysql_select_db(_handle->mysql.get(), _handle->config->database.c_str()))
{
delete _handle;
throw sqlpp::exception("MySQL error: can't select database '" + _handle->config->database + "'");
}
} Maybe it's good to take a look to |
Are you sure you are using the latest version? If so, which program are you running with valgrind? Deleting There was a problem in case For
Hope this is it now. In any case, thanks for pushing! |
Run Valgrind like this (include
|
@rbock I think I correctly updated |
Sure, that's what I do. And it says Have you tried with the code I pushed today (like 30mins ago)? |
Also, can you please make sure that you are using either the
or
(See tests) These make sure to initialize the mysql library and free its resources when you are done. Thanks! |
@rbock finally, with latest changes + calling Thanks a lot! |
Awesome! Thanks for your help :-) |
sqlpp11-connector-mysql/src/connection.cpp
Lines 139 to 151 in e85d2ae
_handle
is init with a new object, but if an exception is thrown by the constructor this memory is not deleted due the fact C++ will not call the destructor due the invalid object creation.Memory should delete in the constructor itself before throwing the exception.
The text was updated successfully, but these errors were encountered: