Skip to content
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

Memory leak in Object mapping #913

Open
dyatlovk opened this issue Jan 31, 2024 · 1 comment
Open

Memory leak in Object mapping #913

dyatlovk opened this issue Jan 31, 2024 · 1 comment
Labels
Question Further information is requested

Comments

@dyatlovk
Copy link

Hi.

Memory is allocated but not freed.
Oatpp v1.3.0

static Type* createType() {
Type::Info info;
info.nameQualifier = T::Z__CLASS_TYPE_NAME();
info.polymorphicDispatcher = new PolymorphicDispatcher();
info.parent = T::getParentType();
return new Type(CLASS_ID, info);
}

Valgrind report:

==28656==
==28656== HEAP SUMMARY:
==28656==     in use at exit: 384 bytes in 6 blocks
==28656==   total heap usage: 900 allocs, 894 frees, 605,721 bytes allocated
==28656==
==28656== 8 bytes in 1 blocks are still reachable in loss record 1 of 6
==28656==    at 0x484100F: operator new(unsigned long) (vg_replace_malloc.c:472)
==28656==    by 0x227AC2: oatpp::data::mapping::type::__class::Object<oatpp::postgresql::(anonymous namespace)::VersionRow>::getType() (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x230082: oatpp::postgresql::Executor::getSchemaVersion(oatpp::data::mapping::type::String const&, oatpp::provider::ResourceHandle<oatpp::orm::Connection> const&) (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x1C67EC: oatpp::orm::SchemaMigration::migrate() (src/oatpp/orm/SchemaMigration.cpp:56)
==28656==    by 0x150D67: CustomerDb::CustomerDb(std::shared_ptr<oatpp::orm::Executor> const&) (src/Components/../Db/CustomerDb.hpp:24)
==28656==    by 0x150A72: void std::_Construct<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor>&>(CustomerDb*, std::shared_ptr<oatpp::postgresql::Executor>&) (stl_construct.h:119)
==28656==    by 0x15063D: construct<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor> &> (alloc_traits.h:660)
==28656==    by 0x15063D: std::_Sp_counted_ptr_inplace<CustomerDb, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<std::shared_ptr<oatpp::postgresql::Executor>&>(std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:604)
==28656==    by 0x150471: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<CustomerDb, std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(CustomerDb*&, std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:972)
==28656==    by 0x1503AB: std::__shared_ptr<CustomerDb, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:1712)
==28656==    by 0x150339: std::shared_ptr<CustomerDb>::shared_ptr<std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr.h:464)
==28656==    by 0x14FA98: std::shared_ptr<CustomerDb> std::make_shared<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor>&>(std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr.h:1009)
==28656==    by 0x143805: DbComponent::customerClient::{lambda()#1}::operator()() const (src/Components/DbComponent.hpp:34)
==28656==
==28656== 8 bytes in 1 blocks are still reachable in loss record 2 of 6
==28656==    at 0x484100F: operator new(unsigned long) (vg_replace_malloc.c:472)
==28656==    by 0x227C62: oatpp::data::mapping::type::__class::Object<oatpp::postgresql::(anonymous namespace)::VersionRow>::getType() (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x230082: oatpp::postgresql::Executor::getSchemaVersion(oatpp::data::mapping::type::String const&, oatpp::provider::ResourceHandle<oatpp::orm::Connection> const&) (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x1C67EC: oatpp::orm::SchemaMigration::migrate() (src/oatpp/orm/SchemaMigration.cpp:56)
==28656==    by 0x150D67: CustomerDb::CustomerDb(std::shared_ptr<oatpp::orm::Executor> const&) (src/Components/../Db/CustomerDb.hpp:24)
==28656==    by 0x150A72: void std::_Construct<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor>&>(CustomerDb*, std::shared_ptr<oatpp::postgresql::Executor>&) (stl_construct.h:119)
==28656==    by 0x15063D: construct<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor> &> (alloc_traits.h:660)
==28656==    by 0x15063D: std::_Sp_counted_ptr_inplace<CustomerDb, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<std::shared_ptr<oatpp::postgresql::Executor>&>(std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:604)
==28656==    by 0x150471: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<CustomerDb, std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(CustomerDb*&, std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:972)
==28656==    by 0x1503AB: std::__shared_ptr<CustomerDb, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:1712)
==28656==    by 0x150339: std::shared_ptr<CustomerDb>::shared_ptr<std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr.h:464)
==28656==    by 0x14FA98: std::shared_ptr<CustomerDb> std::make_shared<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor>&>(std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr.h:1009)
==28656==    by 0x143805: DbComponent::customerClient::{lambda()#1}::operator()() const (src/Components/DbComponent.hpp:34)
==28656==
==28656== 8 bytes in 1 blocks are still reachable in loss record 3 of 6
==28656==    at 0x484100F: operator new(unsigned long) (vg_replace_malloc.c:472)
==28656==    by 0x2300B9: oatpp::postgresql::Executor::getSchemaVersion(oatpp::data::mapping::type::String const&, oatpp::provider::ResourceHandle<oatpp::orm::Connection> const&) (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x1C67EC: oatpp::orm::SchemaMigration::migrate() (src/oatpp/orm/SchemaMigration.cpp:56)
==28656==    by 0x150D67: CustomerDb::CustomerDb(std::shared_ptr<oatpp::orm::Executor> const&) (src/Components/../Db/CustomerDb.hpp:24)
==28656==    by 0x150A72: void std::_Construct<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor>&>(CustomerDb*, std::shared_ptr<oatpp::postgresql::Executor>&) (stl_construct.h:119)
==28656==    by 0x15063D: construct<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor> &> (alloc_traits.h:660)
==28656==    by 0x15063D: std::_Sp_counted_ptr_inplace<CustomerDb, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<std::shared_ptr<oatpp::postgresql::Executor>&>(std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:604)
==28656==    by 0x150471: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<CustomerDb, std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(CustomerDb*&, std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:972)
==28656==    by 0x1503AB: std::__shared_ptr<CustomerDb, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:1712)
==28656==    by 0x150339: std::shared_ptr<CustomerDb>::shared_ptr<std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr.h:464)
==28656==    by 0x14FA98: std::shared_ptr<CustomerDb> std::make_shared<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor>&>(std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr.h:1009)
==28656==    by 0x143805: DbComponent::customerClient::{lambda()#1}::operator()() const (src/Components/DbComponent.hpp:34)
==28656==    by 0x13DFEB: DbComponent::DbComponent() (src/Components/DbComponent.hpp:28)
==28656==
==28656== 104 bytes in 1 blocks are still reachable in loss record 4 of 6
==28656==    at 0x484100F: operator new(unsigned long) (vg_replace_malloc.c:472)
==28656==    by 0x22909D: oatpp::data::mapping::type::__class::Object<oatpp::postgresql::(anonymous namespace)::VersionRow>::PolymorphicDispatcher::createObject() const (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x2848F8: oatpp::postgresql::mapping::ResultMapper::readOneRowAsObject(oatpp::postgresql::mapping::ResultMapper*, oatpp::postgresql::mapping::ResultMapper::ResultData*, oatpp::data::mapping::type::Type const*, long) (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x28525A: oatpp::postgresql::mapping::ResultMapper::readRowsAsCollection(oatpp::postgresql::mapping::ResultMapper*, oatpp::postgresql::mapping::ResultMapper::ResultData*, oatpp::data::mapping::type::Type const*, long) (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x28463C: oatpp::postgresql::mapping::ResultMapper::readRows(oatpp::postgresql::mapping::ResultMapper::ResultData*, oatpp::data::mapping::type::Type const*, long) (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x2348FD: oatpp::postgresql::QueryResult::fetch(oatpp::data::mapping::type::Type const*, long) (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x22F78A: oatpp::postgresql::Executor::getSchemaVersion(oatpp::data::mapping::type::String const&, oatpp::provider::ResourceHandle<oatpp::orm::Connection> const&) (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x1C67EC: oatpp::orm::SchemaMigration::migrate() (src/oatpp/orm/SchemaMigration.cpp:56)
==28656==    by 0x150D67: CustomerDb::CustomerDb(std::shared_ptr<oatpp::orm::Executor> const&) (src/Components/../Db/CustomerDb.hpp:24)
==28656==    by 0x150A72: void std::_Construct<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor>&>(CustomerDb*, std::shared_ptr<oatpp::postgresql::Executor>&) (stl_construct.h:119)
==28656==    by 0x15063D: construct<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor> &> (alloc_traits.h:660)
==28656==    by 0x15063D: std::_Sp_counted_ptr_inplace<CustomerDb, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<std::shared_ptr<oatpp::postgresql::Executor>&>(std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:604)
==28656==    by 0x150471: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<CustomerDb, std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(CustomerDb*&, std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:972)
==28656==
==28656== 128 bytes in 1 blocks are still reachable in loss record 5 of 6
==28656==    at 0x484100F: operator new(unsigned long) (vg_replace_malloc.c:472)
==28656==    by 0x227C8B: oatpp::data::mapping::type::__class::Object<oatpp::postgresql::(anonymous namespace)::VersionRow>::getType() (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x230082: oatpp::postgresql::Executor::getSchemaVersion(oatpp::data::mapping::type::String const&, oatpp::provider::ResourceHandle<oatpp::orm::Connection> const&) (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x1C67EC: oatpp::orm::SchemaMigration::migrate() (src/oatpp/orm/SchemaMigration.cpp:56)
==28656==    by 0x150D67: CustomerDb::CustomerDb(std::shared_ptr<oatpp::orm::Executor> const&) (src/Components/../Db/CustomerDb.hpp:24)
==28656==    by 0x150A72: void std::_Construct<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor>&>(CustomerDb*, std::shared_ptr<oatpp::postgresql::Executor>&) (stl_construct.h:119)
==28656==    by 0x15063D: construct<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor> &> (alloc_traits.h:660)
==28656==    by 0x15063D: std::_Sp_counted_ptr_inplace<CustomerDb, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<std::shared_ptr<oatpp::postgresql::Executor>&>(std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:604)
==28656==    by 0x150471: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<CustomerDb, std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(CustomerDb*&, std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:972)
==28656==    by 0x1503AB: std::__shared_ptr<CustomerDb, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:1712)
==28656==    by 0x150339: std::shared_ptr<CustomerDb>::shared_ptr<std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr.h:464)
==28656==    by 0x14FA98: std::shared_ptr<CustomerDb> std::make_shared<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor>&>(std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr.h:1009)
==28656==    by 0x143805: DbComponent::customerClient::{lambda()#1}::operator()() const (src/Components/DbComponent.hpp:34)
==28656==
==28656== 128 bytes in 1 blocks are still reachable in loss record 6 of 6
==28656==    at 0x484100F: operator new(unsigned long) (vg_replace_malloc.c:472)
==28656==    by 0x227AF6: oatpp::data::mapping::type::__class::Object<oatpp::postgresql::(anonymous namespace)::VersionRow>::getType() (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x230082: oatpp::postgresql::Executor::getSchemaVersion(oatpp::data::mapping::type::String const&, oatpp::provider::ResourceHandle<oatpp::orm::Connection> const&) (in /home/calisto/Work/www/cpp/oat_2/build/server)
==28656==    by 0x1C67EC: oatpp::orm::SchemaMigration::migrate() (src/oatpp/orm/SchemaMigration.cpp:56)
==28656==    by 0x150D67: CustomerDb::CustomerDb(std::shared_ptr<oatpp::orm::Executor> const&) (src/Components/../Db/CustomerDb.hpp:24)
==28656==    by 0x150A72: void std::_Construct<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor>&>(CustomerDb*, std::shared_ptr<oatpp::postgresql::Executor>&) (stl_construct.h:119)
==28656==    by 0x15063D: construct<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor> &> (alloc_traits.h:660)
==28656==    by 0x15063D: std::_Sp_counted_ptr_inplace<CustomerDb, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<std::shared_ptr<oatpp::postgresql::Executor>&>(std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:604)
==28656==    by 0x150471: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<CustomerDb, std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(CustomerDb*&, std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:972)
==28656==    by 0x1503AB: std::__shared_ptr<CustomerDb, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr_base.h:1712)
==28656==    by 0x150339: std::shared_ptr<CustomerDb>::shared_ptr<std::allocator<void>, std::shared_ptr<oatpp::postgresql::Executor>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr.h:464)
==28656==    by 0x14FA98: std::shared_ptr<CustomerDb> std::make_shared<CustomerDb, std::shared_ptr<oatpp::postgresql::Executor>&>(std::shared_ptr<oatpp::postgresql::Executor>&) (shared_ptr.h:1009)
==28656==    by 0x143805: DbComponent::customerClient::{lambda()#1}::operator()() const (src/Components/DbComponent.hpp:34)
==28656=
==28656== LEAK SUMMARY:
==28656==    definitely lost: 0 bytes in 0 blocks
==28656==    indirectly lost: 0 bytes in 0 blocks
==28656==      possibly lost: 0 bytes in 0 blocks
==28656==    still reachable: 384 bytes in 6 blocks
==28656==         suppressed: 0 bytes in 0 blocks
==28656==
==28656== For lists of detected and suppressed errors, rerun with: -s
==28656== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

@lganzzzo
Copy link
Member

lganzzzo commented Feb 5, 2024

Hello @dyatlovk ,

This is done on purpose.
All oatpp types information is allocated once and is stored in the memory "forever" until application is closed

@lganzzzo lganzzzo added the Question Further information is requested label Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants