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 thermoPropertiesGasCORK #48

Closed
allanleal opened this issue Nov 21, 2022 · 0 comments · Fixed by #49
Closed

Memory leak in thermoPropertiesGasCORK #48

allanleal opened this issue Nov 21, 2022 · 0 comments · Fixed by #49

Comments

@allanleal
Copy link
Contributor

In method thermoPropertiesGasCORK, file GasCORK.cpp, memory is allocated using new:

double * CPg = new double[7];

but it is never freed.

This was determined using valgrind, when running it over all Reaktoro's C++ tests. This is what it produced:

==1134== 
==1134== HEAP SUMMARY:
==1134==     in use at exit: 56 bytes in 1 blocks
==1134==   total heap usage: 144,625,352 allocs, 144,625,351 frees, 25,275,031,795 bytes allocated
==1134== 
==1134== 56 bytes in 1 blocks are definitely lost in loss record 1 of 1
==1134==    at 0x483C583: operator new[](unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==1134==    by 0x7C9D4F8: ThermoFun::thermoPropertiesGasCORK(Reaktoro_::Temperature, Reaktoro_::Pressure, ThermoFun::Substance, ThermoFun::ThermoPropertiesSubstance) (in /home/allan/miniconda3/envs/reaktoro/lib/libThermoFun.so)
==1134==    by 0x7D9167F: ThermoFun::GasCORK::thermoProperties(double, double, ThermoFun::ThermoPropertiesSubstance) (in /home/allan/miniconda3/envs/reaktoro/lib/libThermoFun.so)
==1134==    by 0x7D7F541: ThermoFun::ThermoEngine::Impl::thermoPropertiesSubstance(double, double&, ThermoFun::Substance const&) (in /home/allan/miniconda3/envs/reaktoro/lib/libThermoFun.so)
==1134==    by 0x7D7FE20: ThermoFun::ThermoEngine::thermoPropertiesSubstance(double, double&, ThermoFun::Substance const&) const (in /home/allan/miniconda3/envs/reaktoro/lib/libThermoFun.so)
==1134==    by 0x7857830: Reaktoro::ThermoFunEngine::Impl::props(autodiff::detail::Real<1ul, double> const&, autodiff::detail::Real<1ul, double> const&, ThermoFun::Substance const&) const (in /home/allan/codes/reaktoro/build/debug/gcc/Reaktoro/libReaktoro.so)
==1134==    by 0x784EB17: Reaktoro::ThermoFunEngine::props(autodiff::detail::Real<1ul, double> const&, autodiff::detail::Real<1ul, double> const&, ThermoFun::Substance const&) const (in /home/allan/codes/reaktoro/build/debug/gcc/Reaktoro/libReaktoro.so)
==1134==    by 0x7834CF9: Reaktoro::(anonymous namespace)::createStandardThermoModel(Reaktoro::ThermoFunEngine const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::{lambda(autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double>)#1}::operator()(autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double>) const (in /home/allan/codes/reaktoro/build/debug/gcc/Reaktoro/libReaktoro.so)
==1134==    by 0x78363FF: Reaktoro::StandardThermoProps std::__invoke_impl<Reaktoro::StandardThermoProps, Reaktoro::(anonymous namespace)::createStandardThermoModel(Reaktoro::ThermoFunEngine const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::{lambda(autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double>)#1}&, autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double> >(std::__invoke_other, Reaktoro::(anonymous namespace)::createStandardThermoModel(Reaktoro::ThermoFunEngine const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::{lambda(autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double>)#1}&, autodiff::detail::Real<1ul, double>&&, autodiff::detail::Real<1ul, double>&&) (in /home/allan/codes/reaktoro/build/debug/gcc/Reaktoro/libReaktoro.so)
==1134==    by 0x783629A: std::enable_if<is_invocable_r_v<Reaktoro::StandardThermoProps, Reaktoro::(anonymous namespace)::createStandardThermoModel(Reaktoro::ThermoFunEngine const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::{lambda(autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double>)#1}&, autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double> >, std::enable_if>::type std::__invoke_r<Reaktoro::StandardThermoProps, Reaktoro::(anonymous namespace)::createStandardThermoModel(Reaktoro::ThermoFunEngine const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::{lambda(autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double>)#1}&, autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double> >(Reaktoro::StandardThermoProps&&, (Reaktoro::(anonymous namespace)::createStandardThermoModel(Reaktoro::ThermoFunEngine const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::{lambda(autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double>)#1}&)...) (in /home/allan/codes/reaktoro/build/debug/gcc/Reaktoro/libReaktoro.so)
==1134==    by 0x78360BD: std::_Function_handler<Reaktoro::StandardThermoProps (autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double>), Reaktoro::(anonymous namespace)::createStandardThermoModel(Reaktoro::ThermoFunEngine const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::{lambda(autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double>)#1}>::_M_invoke(std::_Any_data const&, autodiff::detail::Real<1ul, double>&&, std::_Any_data const&) (in /home/allan/codes/reaktoro/build/debug/gcc/Reaktoro/libReaktoro.so)
==1134==    by 0x7994E4: std::function<Reaktoro::StandardThermoProps (autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double>)>::operator()(autodiff::detail::Real<1ul, double>, autodiff::detail::Real<1ul, double>) const (in /home/allan/codes/reaktoro/build/debug/gcc/Reaktoro/reaktoro-cpptests)
==1134== 
==1134== LEAK SUMMARY:
==1134==    definitely lost: 56 bytes in 1 blocks
==1134==    indirectly lost: 0 bytes in 0 blocks
==1134==      possibly lost: 0 bytes in 0 blocks
==1134==    still reachable: 0 bytes in 0 blocks
==1134==         suppressed: 0 bytes in 0 blocks
==1134== 
==1134== For lists of detected and suppressed errors, rerun with: -s
==1134== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant