Memory Corruption
After adding the following 2 lines in CMakeLists.txt: SET(CMAKE_CXX_COMPILER "clang++") SET (CMAKE_CXX_FLAGS_DEBUG "-O0 -g -fstack-check -fstack-protector-strong -finstrument-functions -fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-omit-frame-pointer -static-libsan")
and building and running executable, I get the following segmentation fault. This also happens in other examples as well. These errors are not detected without adding the above lines.
/home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:17:3: runtime error: member access within address 0x7f3e947fa860 which does not point to an object of type 'MyDto::Z__CLASS' (aka 'MyDto') 0x7f3e947fa860: note: object has a possibly invalid vptr: abs(offset to top) too big 72 55 00 00 90 a8 7f 94 3e 7f 00 00 81 79 87 bc 72 55 00 00 f0 fa 45 bd 72 55 00 00 44 e8 84 bc ^~~~~~~~~~~~~~~~~~~~~~~ possibly invalid vptr SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:17:3 in AddressSanitizer:DEADLYSIGNAL
==24104==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x7f3e987fcd4b bp 0x5572bca72b20 sp 0x7f3e947fa4b0 T4)
==24104==The signal is caused by a READ memory access.
==24104==Hint: this fault was caused by a dereference of a high value address (see register values below). Disassemble the provided pc to learn which register was used.
#0 0x7f3e987fcd4b in __dynamic_cast (/lib/x86_64-linux-gnu/libstdc++.so.6+0xacd4b) (BuildId: 725ef5da52ee6d881f9024d8238a989903932637)
#1 0x5572bc8249fb in __ubsan::checkDynamicType(void*, void*, unsigned long) (/home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/build/my-project-test+0x3379fb) (BuildId: df7951fc96518e964f34d4da5a9afa4b46591cd3)
#2 0x5572bc823b42 in HandleDynamicTypeCacheMiss(__ubsan::DynamicTypeCacheMissData*, unsigned long, unsigned long, __ubsan::ReportOptions) ubsan_handlers_cxx.cpp.o
#3 0x5572bc823b0d in __ubsan_handle_dynamic_type_cache_miss (/home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/build/my-project-test+0x336b0d) (BuildId: df7951fc96518e964f34d4da5a9afa4b46591cd3)
#4 0x5572bc87a71c in MyDto::Z__PROPERTY_OFFSET_message() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:18:3
#5 0x5572bc87a49d in MyDto::Z__PROPERTY_SINGLETON_message() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:18:3
#6 0x5572bc87a32c in MyDto::Z__PROPERTY_INIT_message(...) /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:18:3
#7 0x5572bc8768cf in MyDto::Z__PROPERTY_INITIALIZER_PROXY_message() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:18:3
#8 0x5572bc876717 in MyDto::MyDto() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:18:3
#9 0x5572bc876618 in void std::_Construct<MyDto>(MyDto*) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_construct.h:119:25
#10 0x5572bc875ca0 in void std::allocator_traits<std::allocator
AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV (/lib/x86_64-linux-gnu/libstdc++.so.6+0xacd4b) (BuildId: 725ef5da52ee6d881f9024d8238a989903932637) in __dynamic_cast Thread T4 created by T1 here: #0 0x5572bc7d0d8c in __interceptor_pthread_create (/home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/build/my-project-test+0x2e3d8c) (BuildId: df7951fc96518e964f34d4da5a9afa4b46591cd3) #1 0x7f3e9882c398 in std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_deletestd::thread::_State >, void (*)()) (/lib/x86_64-linux-gnu/libstdc++.so.6+0xdc398) (BuildId: 725ef5da52ee6d881f9024d8238a989903932637) #2 0x5572bc921bd5 in oatpp::web::server::HttpConnectionHandler::handleConnection(oatpp::provider::ResourceHandleoatpp::data::stream::IOStream const&, std::shared_ptr<std::unordered_map<oatpp::data::mapping::type::String, oatpp::data::mapping::type::String, std::hashoatpp::data::mapping::type::String, std::equal_tooatpp::data::mapping::type::String, std::allocator<std::pair<oatpp::data::mapping::type::String const, oatpp::data::mapping::type::String> > > const> const&) /home/manju/tools/oatpp_repos/oatpp/src/oatpp/web/server/HttpConnectionHandler.cpp:105:113 #3 0x5572bc8e3a4f in oatpp::network::Server::conditionalMainLoop() /home/manju/tools/oatpp_repos/oatpp/src/oatpp/network/Server.cpp:60:50 #4 0x5572bc8e3ee1 in oatpp::network::Server::run(std::function<bool ()>) /home/manju/tools/oatpp_repos/oatpp/src/oatpp/network/Server.cpp:113:24 #5 0x5572bc82a593 in void oatpp::test::web::ClientServerTestRunner::runMyControllerTest::onRun()::$_0(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()::operator()() const /usr/local/include/oatpp-1.3.0/oatpp/oatpp-test/web/ClientServerTestRunner.hpp:104:17 #6 0x5572bc82a2a4 in MyControllerTest::onRun()::$_0 std::__invoke_impl<void, void oatpp::test::web::ClientServerTestRunner::runMyControllerTest::onRun()::$_0(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()>(std::__invoke_other, void oatpp::test::web::ClientServerTestRunner::runMyControllerTest::onRun()::$_0(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:61:14 #7 0x5572bc82a044 in std::__invoke_resultMyControllerTest::onRun()::$_0::type std::__invoke<void oatpp::test::web::ClientServerTestRunner::runMyControllerTest::onRun()::$_0(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()>(MyControllerTest::onRun()::$_0&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:96:14 #8 0x5572bc829f88 in void std::thread::_Invoker<std::tuple<void oatpp::test::web::ClientServerTestRunner::runMyControllerTest::onRun()::$_0(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()> >::_M_invoke<0ul>(std::_Index_tuple<0ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_thread.h:252:13 #9 0x5572bc829e60 in std::thread::_Invoker<std::tuple<void oatpp::test::web::ClientServerTestRunner::runMyControllerTest::onRun()::$_0(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()> >::operator()() /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_thread.h:259:11 #10 0x5572bc829be0 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void oatpp::test::web::ClientServerTestRunner::runMyControllerTest::onRun()::$_0(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()> > >::_M_run() /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_thread.h:210:13 #11 0x7f3e9882c2c2 (/lib/x86_64-linux-gnu/libstdc++.so.6+0xdc2c2) (BuildId: 725ef5da52ee6d881f9024d8238a989903932637)
Thread T1 created by T0 here: #0 0x5572bc7d0d8c in __interceptor_pthread_create (/home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/build/my-project-test+0x2e3d8c) (BuildId: df7951fc96518e964f34d4da5a9afa4b46591cd3) #1 0x7f3e9882c398 in std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_deletestd::thread::_State >, void (*)()) (/lib/x86_64-linux-gnu/libstdc++.so.6+0xdc398) (BuildId: 725ef5da52ee6d881f9024d8238a989903932637) #2 0x5572bc826d69 in void oatpp::test::web::ClientServerTestRunner::runMyControllerTest::onRun()::$_0(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&) /usr/local/include/oatpp-1.3.0/oatpp/oatpp-test/web/ClientServerTestRunner.hpp:103:17 #3 0x5572bc825e00 in MyControllerTest::onRun() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/test/MyControllerTest.cpp:24:10 #4 0x5572bc8b3a70 in oatpp::test::UnitTest::run(int) /home/manju/tools/oatpp_repos/oatpp/src/oatpp-test/UnitTest.cpp:43:10 #5 0x5572bc825431 in void oatpp::test::UnitTest::runTest<MyControllerTest>(int) /usr/local/include/oatpp-1.3.0/oatpp/oatpp-test/UnitTest.hpp:89:10 #6 0x5572bc824cf5 in runTests() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/test/tests.cpp:7:3 #7 0x5572bc824e20 in main /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/test/tests.cpp:14:3 #8 0x7f3e9844ad8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16