We are developing Linux service application based on Ubuntu 22.04 and C++20 and the application connects to AWS Redshift service using unixODBC.
In debug build we are running ASAN with enabled LeakSanitizer, that records memory leak originating from SQLDriverConnect.
I have the following (latest & greatest that time when the problem discovered) driver installed:
https://s3.amazonaws.com/redshift-downloads/drivers/odbc/1.4.59.1000/AmazonRedshiftODBC-64-bit-1.4.59.1000-1.x86_64.deb
I also tried with an earlier version of Redshift ODBC driver too.
Running the following command line, I can constantly reproduce the following memory leak report:
ASAN_OPTIONS=verbosity=1:fast_unwind_on_malloc=0:check_initialization_order=1 ./memleak
The minimal example to reproduce the program:
#include <iostream>
#include <sql.h>
#include <sqlext.h>
#include <string>
int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv_char[], __attribute__((unused)) char* env_char[]) {
SQLHENV env = nullptr;
std::cerr << SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env) << std::endl;
std::cerr << SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, reinterpret_cast<SQLPOINTER>(SQL_OV_ODBC3), 0) << std::endl;
SQLHDBC dbc = nullptr;
std::cerr << SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc) << std::endl;
std::cerr << SQLSetConnectAttr(dbc, SQL_ATTR_AUTOCOMMIT, reinterpret_cast<SQLPOINTER>(true), 0) << std::endl;
std::string connectionString = "Driver={Amazon Redshift (x64)};Server=<...>;Port=5439;Database=<...>;UID=<...>;PWD=<...>";
std::cerr << SQLDriverConnect(dbc, nullptr, (SQLCHAR*)connectionString.c_str(), connectionString.size(), nullptr, 0, nullptr, SQL_DRIVER_COMPLETE) << std::endl;
std::cerr << SQLDisconnect(dbc) << std::endl;
std::cerr << SQLFreeHandle(SQL_HANDLE_DBC, dbc) << std::endl;
std::cerr << SQLFreeHandle(SQL_HANDLE_ENV, env) << std::endl;
return 0;
}
The ASAN log output:
==30839==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 72 byte(s) in 1 object(s) allocated from:
#0 0x55a8d3ea9db8 in __interceptor_calloc (/.../build-...-Clang_14-Debug/.../memleak+0xa3db8) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
#1 0x7f21fa8b4f8e (<unknown module>)
#2 0x7f21fa8b534c (<unknown module>)
#3 0x7f21fb606f19 in Simba::ODBC::ODBCIniReader::GetKeyValuePairs(Simba::ODBC::ODBCIniReader::Source, Simba::Support::simba_wstring const&, std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > >&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3bf19)
#4 0x7f21fb6093fe in Simba::ODBC::ConnectionSettings::LoadFromOdbcIni(Simba::Support::simba_wstring const&, std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > >&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3e3fe)
#5 0x7f21fb609a3a in Simba::ODBC::ConnectionSettings::LoadODBCSettings() (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3ea3a)
#6 0x7f21fb60a427 in Simba::ODBC::ConnectionSettings::LoadSettings(Simba::Support::simba_wstring const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3f427)
#7 0x7f21fb60a764 in Simba::ODBC::ConnectionSettings::ConnectionSettings(Simba::Support::simba_wstring const&, Simba::ODBC::Connection&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3f764)
#8 0x7f21fb601c24 in Simba::ODBC::ConnectionState2::SQLDriverConnectW(Simba::ODBC::Connection*, void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb36c24)
#9 0x7f21fb5f5220 in Simba::ODBC::Connection::SQLDriverConnectW(void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb2a220)
#10 0x7f21fb5b3133 in Simba::ODBC::SQLDriverConnectTask<false>::DoSynchronously(Simba::ODBC::Connection&, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae8133)
#11 0x7f21fb5c6e5a in short DoTask<Simba::ODBC::SQLDriverConnectTask<false> >(char const*, void*, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xafbe5a)
#12 0x7f21fb5b35e4 in SQLDriverConnect (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae85e4)
#13 0x7f22018555a6 in SQLDriverConnect /bamboo/unixODBC-2.3.7/DriverManager/SQLDriverConnect.c:1376
#14 0x55a8d3ee7a06 in main /.../.../.../.../Memleak.cpp:18:18
#15 0x7f220119a082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#16 0x55a8d3e274bd in _start (/.../build-...-Clang_14-Debug/.../memleak+0x214bd) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
Direct leak of 16 byte(s) in 1 object(s) allocated from:
#0 0x55a8d3ea9bce in malloc (/.../build-...-Clang_14-Debug/.../memleak+0xa3bce) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
#1 0x7f21fbea8967 in operator new(unsigned long) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x13dd967)
#2 0x7f21fb1c2538 in Simba::Support::AttributeData::MakeNewWStringAttributeData(Simba::Support::simba_wstring*) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x6f7538)
#3 0x7f21fad8b198 in Simba::PostgreSQLODBC::PGOConnection::HandleConnect(std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > > const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x2c0198)
#4 0x7f21fb68eb2e in Simba::DriverSupport::DSCommonConnection::Connect(Simba::DSI::ConnectionSettingsRequest const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xbc3b2e)
#5 0x7f21fb5fbcfc in Simba::ODBC::Connection::CompleteConnection(Simba::ODBC::ConnectionSettings&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb30cfc)
#6 0x7f21fb601c75 in Simba::ODBC::ConnectionState2::SQLDriverConnectW(Simba::ODBC::Connection*, void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb36c75)
#7 0x7f21fb5f5220 in Simba::ODBC::Connection::SQLDriverConnectW(void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb2a220)
#8 0x7f21fb5b3133 in Simba::ODBC::SQLDriverConnectTask<false>::DoSynchronously(Simba::ODBC::Connection&, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae8133)
#9 0x7f21fb5c6e5a in short DoTask<Simba::ODBC::SQLDriverConnectTask<false> >(char const*, void*, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xafbe5a)
#10 0x7f21fb5b35e4 in SQLDriverConnect (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae85e4)
#11 0x7f22018555a6 in SQLDriverConnect /bamboo/unixODBC-2.3.7/DriverManager/SQLDriverConnect.c:1376
#12 0x55a8d3ee7a06 in main /.../.../.../.../Memleak.cpp:18:18
#13 0x7f220119a082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#14 0x55a8d3e274bd in _start (/.../build-...-Clang_14-Debug/.../memleak+0x214bd) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
Indirect leak of 176 byte(s) in 1 object(s) allocated from:
#0 0x55a8d3ea9bce in malloc (/.../build-...-Clang_14-Debug/.../memleak+0xa3bce) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
#1 0x7f21fb131fa6 in sbicu_58__sb64::UnicodeString::allocate(int) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x666fa6)
#2 0x7f21fb132307 in sbicu_58__sb64::UnicodeString::UnicodeString(int, int, int) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x667307)
#3 0x7f21fb2165d4 in Simba::Support::simba_wstring::GetWritableBuffer(int) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x74b5d4)
#4 0x7f21fb23a712 in Simba::Support::WideStringConverter::ConvertToWString(unsigned char const*, int, Simba::Support::EncodingType, Simba::Support::simba_wstring&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x76f712)
#5 0x7f21fad8b190 in Simba::PostgreSQLODBC::PGOConnection::HandleConnect(std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > > const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x2c0190)
#6 0x7f21fb68eb2e in Simba::DriverSupport::DSCommonConnection::Connect(Simba::DSI::ConnectionSettingsRequest const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xbc3b2e)
#7 0x7f21fb5fbcfc in Simba::ODBC::Connection::CompleteConnection(Simba::ODBC::ConnectionSettings&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb30cfc)
#8 0x7f21fb601c75 in Simba::ODBC::ConnectionState2::SQLDriverConnectW(Simba::ODBC::Connection*, void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb36c75)
#9 0x7f21fb5f5220 in Simba::ODBC::Connection::SQLDriverConnectW(void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb2a220)
#10 0x7f21fb5b3133 in Simba::ODBC::SQLDriverConnectTask<false>::DoSynchronously(Simba::ODBC::Connection&, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae8133)
#11 0x7f21fb5c6e5a in short DoTask<Simba::ODBC::SQLDriverConnectTask<false> >(char const*, void*, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xafbe5a)
#12 0x7f21fb5b35e4 in SQLDriverConnect (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae85e4)
#13 0x7f22018555a6 in SQLDriverConnect /bamboo/unixODBC-2.3.7/DriverManager/SQLDriverConnect.c:1376
#14 0x55a8d3ee7a06 in main /.../.../.../.../Memleak.cpp:18:18
#15 0x7f220119a082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#16 0x55a8d3e274bd in _start (/.../build-...-Clang_14-Debug/.../memleak+0x214bd) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x55a8d3ea9bce in malloc (/.../build-...-Clang_14-Debug/.../memleak+0xa3bce) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
#1 0x7f21fb0cf2c8 in sbicu_58__sb64::UMemory::operator new(unsigned long) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x6042c8)
#2 0x7f21fb213d90 in Simba::Support::simba_wstring::simba_wstring(Simba::Support::simba_wstring const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x748d90)
#3 0x7f21fb1c25d0 in Simba::Support::AttributeData::MakeNewWStringAttributeData(Simba::Support::simba_wstring const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x6f75d0)
#4 0x7f21fad8b198 in Simba::PostgreSQLODBC::PGOConnection::HandleConnect(std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > > const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x2c0198)
#5 0x7f21fb68eb2e in Simba::DriverSupport::DSCommonConnection::Connect(Simba::DSI::ConnectionSettingsRequest const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xbc3b2e)
#6 0x7f21fb5fbcfc in Simba::ODBC::Connection::CompleteConnection(Simba::ODBC::ConnectionSettings&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb30cfc)
#7 0x7f21fb601c75 in Simba::ODBC::ConnectionState2::SQLDriverConnectW(Simba::ODBC::Connection*, void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb36c75)
#8 0x7f21fb5f5220 in Simba::ODBC::Connection::SQLDriverConnectW(void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb2a220)
#9 0x7f21fb5b3133 in Simba::ODBC::SQLDriverConnectTask<false>::DoSynchronously(Simba::ODBC::Connection&, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae8133)
#10 0x7f21fb5c6e5a in short DoTask<Simba::ODBC::SQLDriverConnectTask<false> >(char const*, void*, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xafbe5a)
#11 0x7f21fb5b35e4 in SQLDriverConnect (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae85e4)
#12 0x7f22018555a6 in SQLDriverConnect /bamboo/unixODBC-2.3.7/DriverManager/SQLDriverConnect.c:1376
#13 0x55a8d3ee7a06 in main /.../.../.../.../Memleak.cpp:18:18
#14 0x7f220119a082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#15 0x55a8d3e274bd in _start (/.../build-...-Clang_14-Debug/.../memleak+0x214bd) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
Indirect leak of 10 byte(s) in 1 object(s) allocated from:
#0 0x55a8d3e94933 in __interceptor___strdup (/.../build-...-Clang_14-Debug/.../memleak+0x8e933) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
#1 0x7f21fa8b4fa8 (<unknown module>)
#2 0x7f21fa8b534c (<unknown module>)
#3 0x7f21fb606f19 in Simba::ODBC::ODBCIniReader::GetKeyValuePairs(Simba::ODBC::ODBCIniReader::Source, Simba::Support::simba_wstring const&, std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > >&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3bf19)
#4 0x7f21fb6093fe in Simba::ODBC::ConnectionSettings::LoadFromOdbcIni(Simba::Support::simba_wstring const&, std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > >&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3e3fe)
#5 0x7f21fb609a3a in Simba::ODBC::ConnectionSettings::LoadODBCSettings() (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3ea3a)
#6 0x7f21fb60a427 in Simba::ODBC::ConnectionSettings::LoadSettings(Simba::Support::simba_wstring const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3f427)
#7 0x7f21fb60a764 in Simba::ODBC::ConnectionSettings::ConnectionSettings(Simba::Support::simba_wstring const&, Simba::ODBC::Connection&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3f764)
#8 0x7f21fb601c24 in Simba::ODBC::ConnectionState2::SQLDriverConnectW(Simba::ODBC::Connection*, void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb36c24)
#9 0x7f21fb5f5220 in Simba::ODBC::Connection::SQLDriverConnectW(void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb2a220)
#10 0x7f21fb5b3133 in Simba::ODBC::SQLDriverConnectTask<false>::DoSynchronously(Simba::ODBC::Connection&, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae8133)
#11 0x7f21fb5c6e5a in short DoTask<Simba::ODBC::SQLDriverConnectTask<false> >(char const*, void*, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xafbe5a)
#12 0x7f21fb5b35e4 in SQLDriverConnect (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae85e4)
#13 0x7f22018555a6 in SQLDriverConnect /bamboo/unixODBC-2.3.7/DriverManager/SQLDriverConnect.c:1376
#14 0x55a8d3ee7a06 in main /.../.../.../.../Memleak.cpp:18:18
#15 0x7f220119a082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#16 0x55a8d3e274bd in _start (/.../build-...-Clang_14-Debug/.../memleak+0x214bd) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
Indirect leak of 8 byte(s) in 1 object(s) allocated from:
#0 0x55a8d3ea9bce in malloc (/.../build-...-Clang_14-Debug/.../memleak+0xa3bce) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
#1 0x7f21fbea8967 in operator new(unsigned long) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x13dd967)
#2 0x7f21fb1c25c2 in Simba::Support::AttributeData::MakeNewWStringAttributeData(Simba::Support::simba_wstring const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x6f75c2)
#3 0x7f21fad8b198 in Simba::PostgreSQLODBC::PGOConnection::HandleConnect(std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > > const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0x2c0198)
#4 0x7f21fb68eb2e in Simba::DriverSupport::DSCommonConnection::Connect(Simba::DSI::ConnectionSettingsRequest const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xbc3b2e)
#5 0x7f21fb5fbcfc in Simba::ODBC::Connection::CompleteConnection(Simba::ODBC::ConnectionSettings&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb30cfc)
#6 0x7f21fb601c75 in Simba::ODBC::ConnectionState2::SQLDriverConnectW(Simba::ODBC::Connection*, void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb36c75)
#7 0x7f21fb5f5220 in Simba::ODBC::Connection::SQLDriverConnectW(void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb2a220)
#8 0x7f21fb5b3133 in Simba::ODBC::SQLDriverConnectTask<false>::DoSynchronously(Simba::ODBC::Connection&, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae8133)
#9 0x7f21fb5c6e5a in short DoTask<Simba::ODBC::SQLDriverConnectTask<false> >(char const*, void*, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xafbe5a)
#10 0x7f21fb5b35e4 in SQLDriverConnect (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae85e4)
#11 0x7f22018555a6 in SQLDriverConnect /bamboo/unixODBC-2.3.7/DriverManager/SQLDriverConnect.c:1376
#12 0x55a8d3ee7a06 in main /.../.../.../.../Memleak.cpp:18:18
#13 0x7f220119a082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#14 0x55a8d3e274bd in _start (/.../build-...-Clang_14-Debug/.../memleak+0x214bd) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
Indirect leak of 5 byte(s) in 1 object(s) allocated from:
#0 0x55a8d3e94933 in __interceptor___strdup (/.../build-...-Clang_14-Debug/.../memleak+0x8e933) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
#1 0x7f21fa8b4fb8 (<unknown module>)
#2 0x7f21fa8b534c (<unknown module>)
#3 0x7f21fb606f19 in Simba::ODBC::ODBCIniReader::GetKeyValuePairs(Simba::ODBC::ODBCIniReader::Source, Simba::Support::simba_wstring const&, std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > >&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3bf19)
#4 0x7f21fb6093fe in Simba::ODBC::ConnectionSettings::LoadFromOdbcIni(Simba::Support::simba_wstring const&, std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > >&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3e3fe)
#5 0x7f21fb609a3a in Simba::ODBC::ConnectionSettings::LoadODBCSettings() (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3ea3a)
#6 0x7f21fb60a427 in Simba::ODBC::ConnectionSettings::LoadSettings(Simba::Support::simba_wstring const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3f427)
#7 0x7f21fb60a764 in Simba::ODBC::ConnectionSettings::ConnectionSettings(Simba::Support::simba_wstring const&, Simba::ODBC::Connection&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3f764)
#8 0x7f21fb601c24 in Simba::ODBC::ConnectionState2::SQLDriverConnectW(Simba::ODBC::Connection*, void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb36c24)
#9 0x7f21fb5f5220 in Simba::ODBC::Connection::SQLDriverConnectW(void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb2a220)
#10 0x7f21fb5b3133 in Simba::ODBC::SQLDriverConnectTask<false>::DoSynchronously(Simba::ODBC::Connection&, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae8133)
#11 0x7f21fb5c6e5a in short DoTask<Simba::ODBC::SQLDriverConnectTask<false> >(char const*, void*, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xafbe5a)
#12 0x7f21fb5b35e4 in SQLDriverConnect (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae85e4)
#13 0x7f22018555a6 in SQLDriverConnect /bamboo/unixODBC-2.3.7/DriverManager/SQLDriverConnect.c:1376
#14 0x55a8d3ee7a06 in main /.../.../.../.../Memleak.cpp:18:18
#15 0x7f220119a082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#16 0x55a8d3e274bd in _start (/.../build-...-Clang_14-Debug/.../memleak+0x214bd) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
Indirect leak of 1 byte(s) in 1 object(s) allocated from:
#0 0x55a8d3e94933 in __interceptor___strdup (/.../build-...-Clang_14-Debug/.../memleak+0x8e933) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
#1 0x7f21fa8b4fdf (<unknown module>)
#2 0x7f21fa8b534c (<unknown module>)
#3 0x7f21fb606f19 in Simba::ODBC::ODBCIniReader::GetKeyValuePairs(Simba::ODBC::ODBCIniReader::Source, Simba::Support::simba_wstring const&, std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > >&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3bf19)
#4 0x7f21fb6093fe in Simba::ODBC::ConnectionSettings::LoadFromOdbcIni(Simba::Support::simba_wstring const&, std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > >&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3e3fe)
#5 0x7f21fb609a3a in Simba::ODBC::ConnectionSettings::LoadODBCSettings() (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3ea3a)
#6 0x7f21fb60a427 in Simba::ODBC::ConnectionSettings::LoadSettings(Simba::Support::simba_wstring const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3f427)
#7 0x7f21fb60a764 in Simba::ODBC::ConnectionSettings::ConnectionSettings(Simba::Support::simba_wstring const&, Simba::ODBC::Connection&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3f764)
#8 0x7f21fb601c24 in Simba::ODBC::ConnectionState2::SQLDriverConnectW(Simba::ODBC::Connection*, void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb36c24)
#9 0x7f21fb5f5220 in Simba::ODBC::Connection::SQLDriverConnectW(void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb2a220)
#10 0x7f21fb5b3133 in Simba::ODBC::SQLDriverConnectTask<false>::DoSynchronously(Simba::ODBC::Connection&, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae8133)
#11 0x7f21fb5c6e5a in short DoTask<Simba::ODBC::SQLDriverConnectTask<false> >(char const*, void*, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xafbe5a)
#12 0x7f21fb5b35e4 in SQLDriverConnect (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae85e4)
#13 0x7f22018555a6 in SQLDriverConnect /bamboo/unixODBC-2.3.7/DriverManager/SQLDriverConnect.c:1376
#14 0x55a8d3ee7a06 in main /.../.../.../.../Memleak.cpp:18:18
#15 0x7f220119a082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#16 0x55a8d3e274bd in _start (/.../build-...-Clang_14-Debug/.../memleak+0x214bd) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
Indirect leak of 1 byte(s) in 1 object(s) allocated from:
#0 0x55a8d3e94933 in __interceptor___strdup (/.../build-...-Clang_14-Debug/.../memleak+0x8e933) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
#1 0x7f21fa8b502f (<unknown module>)
#2 0x7f21fa8b534c (<unknown module>)
#3 0x7f21fb606f19 in Simba::ODBC::ODBCIniReader::GetKeyValuePairs(Simba::ODBC::ODBCIniReader::Source, Simba::Support::simba_wstring const&, std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > >&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3bf19)
#4 0x7f21fb6093fe in Simba::ODBC::ConnectionSettings::LoadFromOdbcIni(Simba::Support::simba_wstring const&, std::map<Simba::Support::simba_wstring, Simba::Support::Variant, Simba::Support::simba_wstring::CaseInsensitiveComparator, std::allocator<std::pair<Simba::Support::simba_wstring const, Simba::Support::Variant> > >&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3e3fe)
#5 0x7f21fb609a3a in Simba::ODBC::ConnectionSettings::LoadODBCSettings() (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3ea3a)
#6 0x7f21fb60a427 in Simba::ODBC::ConnectionSettings::LoadSettings(Simba::Support::simba_wstring const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3f427)
#7 0x7f21fb60a764 in Simba::ODBC::ConnectionSettings::ConnectionSettings(Simba::Support::simba_wstring const&, Simba::ODBC::Connection&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb3f764)
#8 0x7f21fb601c24 in Simba::ODBC::ConnectionState2::SQLDriverConnectW(Simba::ODBC::Connection*, void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb36c24)
#9 0x7f21fb5f5220 in Simba::ODBC::Connection::SQLDriverConnectW(void*, wchar_t*, short, wchar_t*, short, short*, unsigned short) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xb2a220)
#10 0x7f21fb5b3133 in Simba::ODBC::SQLDriverConnectTask<false>::DoSynchronously(Simba::ODBC::Connection&, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters const&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae8133)
#11 0x7f21fb5c6e5a in short DoTask<Simba::ODBC::SQLDriverConnectTask<false> >(char const*, void*, Simba::ODBC::SQLDriverConnectTask<false>::TaskParameters&) (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xafbe5a)
#12 0x7f21fb5b35e4 in SQLDriverConnect (/opt/amazon/redshiftodbc/lib/64/libamazonredshiftodbc64.so+0xae85e4)
#13 0x7f22018555a6 in SQLDriverConnect /bamboo/unixODBC-2.3.7/DriverManager/SQLDriverConnect.c:1376
#14 0x55a8d3ee7a06 in main /.../.../.../.../Memleak.cpp:18:18
#15 0x7f220119a082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#16 0x55a8d3e274bd in _start (/.../build-...-Clang_14-Debug/.../memleak+0x214bd) (BuildId: 850d8cc71ac471cad6a45c89d7d3d2ac413d856f)
SUMMARY: AddressSanitizer: 353 byte(s) leaked in 9 allocation(s).
Mock class:
class MockManagerForClient {
public:
MOCK_CONST_METHOD0(GetEngine, std::shared_ptr<engine::Engine>());
MOCK_METHOD1(RemoveClient, void(std::string const& clientId));
virtual ~MockManagerForClient() = default;
};
Test case:
TEST(ClientTest, Login) {
NiceMock<MockManagerForClient> manager;
EXPECT_CALL(manager, RemoveClient(_)).Times(1);
manager.RemoveClient("1");
}
stack capture in gdb:
Catchpoint 1 (signal SIGSEGV), 0x00005555557266f6 in testing::Cardinality::ConservativeUpperBound() const ()
(gdb) bt
#0 0x00005555557266f6 in testing::Cardinality::ConservativeUpperBound() const ()
#1 0x00005555557216c9 in testing::internal::ExpectationBase::CheckActionCountIfNotDone() const ()
#2 0x00005555556ba810 in testing::internal::TypedExpectation<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>::ShouldHandleArguments(std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&> const&) const (this=0x555555a2c8a0, args=std::tuple containing = {...})
at /home/phillip/.conan/data/googletest/1.8.1/phillip/stable/package/efbe354690ef83824a1e98c7a6076b7ab63bc1b3/include/gmock/gmock-spec-builders.h:1111
#3 0x00005555556b9749 in testing::internal::FunctionMockerBase<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>::FindMatchingExpectationLocked(std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&> const&) const (this=0x7fffffffda00, args=std::tuple containing = {...})
at /home/phillip/.conan/data/googletest/1.8.1/phillip/stable/package/efbe354690ef83824a1e98c7a6076b7ab63bc1b3/include/gmock/gmock-spec-builders.h:1739
#4 0x00005555556b8b56 in testing::internal::FunctionMockerBase<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>::UntypedFindMatchingExpectation(void const*, void const**, bool*, std::ostream*, std::ostream*) (this=0x7fffffffda00, untyped_args=0x7fffffffd8f0, untyped_action=0x7fffffffd340, is_excessive=0x7fffffffd337, what=0x7fffffffd3d0, why=0x7fffffffd560)
at /home/phillip/.conan/data/googletest/1.8.1/phillip/stable/package/efbe354690ef83824a1e98c7a6076b7ab63bc1b3/include/gmock/gmock-spec-builders.h:1701
#5 0x000055555572235d in testing::internal::UntypedFunctionMockerBase::UntypedInvokeWith(void*) ()
#6 0x00005555556b56c0 in testing::internal::FunctionMockerBase<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>::InvokeWith(std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>&&) (this=0x7fffffffda00, args=...) at /home/phillip/.conan/data/googletest/1.8.1/phillip/stable/package/efbe354690ef83824a1e98c7a6076b7ab63bc1b3/include/gmock/gmock-spec-builders.h:1602
#7 0x00005555556b4b75 in testing::internal::FunctionMocker<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>::Invoke(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (this=0x7fffffffda00, a1="1") at /home/phillip/.conan/data/googletest/1.8.1/phillip/stable/package/efbe354690ef83824a1e98c7a6076b7ab63bc1b3/include/gmock/gmock-generated-function-mockers.h:101
#8 0x00005555556b46f0 in MockManagerForClient::RemoveClient (this=0x7fffffffd9b0, gmock_a1=...) at /home/phillip/projects/spiral-front/front/engine-test/src/client-impl/./mocks.hpp:33
#9 0x00005555556b3480 in ClientTest_Login_Test::TestBody (this=0x555555a2c1c0) at /home/phillip/projects/spiral-front/front/engine-test/src/client-impl/client-impl-test.cpp:43
#10 0x000055555575f371 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ()
#11 0x000055555575957b in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ()
#12 0x0000555555739298 in testing::Test::Run() ()
#13 0x0000555555739bf5 in testing::TestInfo::Run() ()
#14 0x000055555573a278 in testing::TestCase::Run() ()
#15 0x0000555555745064 in testing::internal::UnitTestImpl::RunAllTests() ()
#16 0x0000555555760519 in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ()
#17 0x000055555575a35f in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ()
#18 0x0000555555743aec in testing::UnitTest::Run() ()
#19 0x00005555556fe830 in RUN_ALL_TESTS () at /home/phillip/.conan/data/googletest/1.8.1/phillip/stable/package/efbe354690ef83824a1e98c7a6076b7ab63bc1b3/include/gtest/gtest.h:2341
#20 0x00005555556fe23c in main (argc=1, argv=0x7fffffffe148) at /home/phillip/projects/spiral-front/front/engine-test/src/main.cpp:7
I have tried several hours and no idea why. I have several others mock class, all works find. The most different of this MockManagerForClient is RemoveClient is return void.
I finally fixed the problem after 2 days. Just like other peoples crash situation, it is due project's compile flags not same as googletest.
My environment is Ubuntu 18.04 with g++ 7.4.0.
To make googletest works with c++11 standard, I use master branch of https://github.com/google/googletest. Build googletest with cmake and check cmake generation file: flags.make
googletest use -std=c++11, will my project use -std=gun++11. So adding following cmake definitions:
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Fixing compile errors due to using c++14 features. Well then the crash issue still there.
Extra compile flags not in my project is: -g -Wall -Wshadow -Werror -Wno-error=dangling-else -DGTEST_HAS_PTHREAD=1 -fexceptions -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
After adding them to my project's CMakeLists.txt and fixing compile errors. googletest crash issue finally gone.
I'm getting a very weird bug when defining a test suite with boost like this:
BOOST_AUTO_TEST_SUITE(zerocoin_implementation_tests)
The error looks like this:
terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_M_create
Here's the relevant backtrace:
#5 0x00007ffff5ce6fe8 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00007ffff5ce2875 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7 0x00007ffff5d7c949 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#8 0x00007ffff70afe15 in boost::unit_test::test_unit::test_unit(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::test_unit_type) () from /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.65.1
#9 0x00007ffff70b0456 in boost::unit_test::test_suite::test_suite(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long) () from /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.65.1
#10 0x00007ffff70b0612 in boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::decorator::collector&) ()
from /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.65.1
From what I can tell, this has to do with Boost trying to create a max length string. I'd like to see exactly what it is doing. What's the best way of expanding boost macros to see the pre-compiled version?
Side Note
Weirdly, if I change the line very slightly to:
BOOST_AUTO_TEST_SUITE(zerocsoin_implementation_tests)
I get the following error:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
And backtrace:
#6 0x00007ffff5ce7594 in operator new(unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7 0x00007ffff70afe15 in boost::unit_test::test_unit::test_unit(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::test_unit_type) () from /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.65.1
#8 0x00007ffff70b0456 in boost::unit_test::test_suite::test_suite(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long) () from /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.65.1
#9 0x00007ffff70b0612 in boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::decorator::collector&) ()
from /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.65.1
The source code for the file (and the rest of the project) can be found here: https://github.com/phoreproject/Phore/blob/segwit/src/test/zerocoin_implementation_tests.cpp
Diff that probably caused the bug: https://github.com/phoreproject/phore/compare/master...segwit#diff-bb4f094cc636d668944ed6af9b72c0d9
Two approaches:
Exception Breakpoints
Just start the test in the debugger and catch the exception.
In gdb you could do
(gdb) catch throw
Catchpoint 2 (throw)
which act like a general breakpoint. Visual Studio has a Manage Exeptions dialog.¹
Boost Test Breakpoints
For debugging Boost Test I like to set a break at the test_method member of the specific test case class I want to break at. E.g. with a test_runner that has a few nested suites like:
./test_runner --list_content
import*
utility*
xml*
xml_utilities*
child_text_test*
loggable_xml_path_test*
And we run these 3 tests like:
./test_runner -t import/utility/xml
Running 3 test cases...
*** No errors detected
To debug them with gdb I'd do
gdb ./test_runner
start -t import/utility/xml
Which stops at main, then I type:
break import::utility::xml
Auto completion helps, so to get the exact names, you can just pick from the completions:
xml
xml::as_element(xmlpp::Node const&)
xml::attr_value(xmlpp::Element const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
xml::attr_value(xmlpp::Node const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
xml::child_text[abi:cxx11](xmlpp::Element const&, char const*)
xml::child_text_test
xml::child_text_test::test_method()
xml::child_text_test_invoker()
xml::child_text_test_registrar62
xml::end_suite94_registrar94
xml::first_child(xmlpp::Element const&, char const*)
xml::get_content[abi:cxx11](xmlpp::Element const&)
xml::get_content[abi:cxx11](xmlpp::Node const*)
xml::is_attr_value(xmlpp::Node const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
xml::loggable_xml_path[abi:cxx11](xmlpp::Node const&)
xml::loggable_xml_path_test
xml::loggable_xml_path_test::test_method()
xml::loggable_xml_path_test_invoker()
xml::loggable_xml_path_test_registrar77
xml::trace_xml(xmlpp::Element const&, LogSource::LogTx)
xml::trace_xml_formatted(xmlpp::Element const&, LogSource::LogTx)
xml::xml_registrar20
xml::xml_utilities
xml::xml_utilities::test_method()
xml::xml_utilities_invoker()
xml::xml_utilities_registrar22
Pick the ones named test_method(), e.g.
break import::utility::xml::child_text_test::test_method()
Breakpoint 2 at 0x730762: file /path/src/import/utility/xml_tests.cpp, line 62.
Now you can continue execution and the debugger will automatic pause execution at the start of your unit test.
¹ see also
Make Visual Studio break on User (std::exception) Exceptions?
How do I make VC++'s debugger break on exceptions?
I've recently updated my Gentoo Linux PC with GCC 5.4.0.
I also recompiled all packages depending on gcc (it was mentioned in gcc upgrade guide for gentoo).
Most of programs works well, however my tests, using cppunit, throw std::bad_alloc before starting.
At first I thought there might be a problem with updated version of cppunit, so I downgraded it to previous version, but the problem still exists.
Whenever I start any test, the application immediately throws:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
I started the application in gdb and printed debug backtrace:
#0 0x00007ffff545d218 in raise () from /lib64/libc.so.6
#1 0x00007ffff545e69a in abort () from /lib64/libc.so.6
#2 0x00007ffff5d8f18d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/libstdc++.so.6
#3 0x00007ffff5d8d046 in ?? () from /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/libstdc++.so.6
#4 0x00007ffff5d8d091 in std::terminate() () from /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/libstdc++.so.6
#5 0x00007ffff5d8d297 in __cxa_throw () from /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/libstdc++.so.6
#6 0x00007ffff5db5f52 in std::__throw_bad_alloc() () from /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/libstdc++.so.6
#7 0x0000000000b2b3ae in __gnu_cxx::new_allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::allocate
(this=0x7fffffffda58, __n=18446741874689290911) at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/ext/new_allocator.h:102
#8 0x0000000000b2b1e2 in std::allocator_traits<std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::allocate (__a=..., __n=18446741874689290911) at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/bits/alloc_traits.h:491
#9 0x0000000000b2b09e in std::__cxx1998::_Vector_base<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_M_allocate (this=0x7fffffffda58,
__n=18446741874689290911) at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/bits/stl_vector.h:170
#10 0x0000000000b2af71 in std::__cxx1998::_Vector_base<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_M_create_storage (this=0x7fffffffda58,
__n=18446741874689290911) at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/bits/stl_vector.h:185
#11 0x0000000000b2acf1 in std::__cxx1998::_Vector_base<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_Vector_base (this=0x7fffffffda58,
__n=18446741874689290911, __a=...) at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/bits/stl_vector.h:136
#12 0x0000000000b29c9c in std::__cxx1998::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::vector (this=0x7fffffffda58,
__x=std::__cxx1998::vector of length -2199020260704, capacity -2199020259433 = {...}) at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/bits/stl_vector.h:320
#13 0x0000000000b29449 in std::__debug::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::vector (this=0x7fffffffda40)
at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/debug/vector:193
#14 0x0000000000b294ef in CppUnit::TestSuiteBuilderContextBase::TestSuiteBuilderContextBase (this=0x7fffffffda20) at /usr/include/cppunit/extensions/TestSuiteBuilderContext.h:29
#15 0x0000000000b29515 in CppUnit::TestSuiteBuilderContext<Types_Decimal>::TestSuiteBuilderContext (this=0x7fffffffda20, contextBase=...) at /usr/include/cppunit/extensions/TestSuiteBuilderContext.h:106
#16 0x0000000000b28a16 in Types_Decimal::addTestsToSuite (baseContext=...) at ./Tests/../../pCpp/CppUnitTests/Types_Decimal.hpp:10
#17 0x0000000000b28caa in Types_Decimal::suite () at ./Tests/../../pCpp/CppUnitTests/Types_Decimal.hpp:12
#18 0x0000000000b2871f in main () at Types_Decimal.cpp:8
There is no problem with test file itself, because I made no changes to it, and lots of test were working for long time.
After looking into stack trace, I'm pretty curious what happened on frame #12: __x=std::**__cxx1998**::vector of length **-2199020260704**, capacity **-2199020259433** = {...}
Why there is cxx1998? Both length and capacity looks pretty insane (uninitialized?).
TestSuiteBuilderContext.h:29:
void
TestSuiteBuilderContextBase::addTest( Test *test )
{
m_suite.addTest( test ); //line 29
}
TestSuite.cpp:
/// Adds a test to the suite.
void
TestSuite::addTest( Test *test )
{
m_tests.push_back( test );
}
I came up with partial solution.
It looks like the compile option:
-D_GLIBCXX_DEBUG
Was causing the problem. After removing it - tests run succesfully.
I encounter a coredump when read file content to std::string. Code is list below:
bool readContentFromFile(const char* fileName, std::string& content)
{
std::ifstream t(fileName);
if(!t) {
return false;
}
t.seekg(0, std::ios::end);
content.reserve(t.tellg());
t.seekg(0, std::ios::beg);
content.assign((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
return true;
}
But occasionally the code cause coredump as below:
...
#4 <signal handler called>
#5 0x00007f347a0f3945 in raise () from /lib64/libc.so.6
#6 0x00007f347a0f4f21 in abort () from /lib64/libc.so.6
#7 0x00007f347a953504 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib64/libstdc++.so.6
#8 0x00007f347a951946 in ?? () from /usr/lib64/libstdc++.so.6
#9 0x00007f347a951973 in std::terminate() () from /usr/lib64/libstdc++.so.6
#10 0x00007f347a951a5a in __cxa_throw () from /usr/lib64/libstdc++.so.6
#11 0x00007f347a8ef2ba in std::__throw_ios_failure(char const*) () from /usr/lib64/libstdc++.so.6
#12 0x00007f347a901317 in std::basic_filebuf<char, std::char_traits<char> >::underflow() () from /usr/lib64/libstdc++.so.6
#13 0x00000000004c2751 in char* std::string::_S_construct<std::istreambuf_iterator<char, std::char_traits<char> > >(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, std::allocator<char> const&, std::input_iterator_tag) ()
#14 0x00000000004c281b in std::string& std::string::_M_replace_dispatch<std::istreambuf_iterator<char, std::char_traits<char> > >(__gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, std::__false_type) ()
#15 0x00000000004bf225 in readContentFromFile(char const*, std::string&) ()
From the above code snippets, exception is throwed in underflow function. But I have no idea why throw exception. The file maybe removed when reading, but which statment in code maybe cause throwing exception?
Pretty clear from the stack trace that the exception is being thrown from content.assign. Looks like string::assign is an inline function which calls std::string::_M_replace_dispatch. You could check this by looking at the header files, or using a debugger. Does that answer the question?