thermohub / thermofun

A code for calculating the standard state thermodynamic properties at a given temperature and pressure.
https://thermohub.org/thermofun/thermofun/
GNU Lesser General Public License v2.1
26 stars 8 forks source link

Memory leak in `thermoPropertiesGasCORK` #48

Closed allanleal closed 1 year ago

allanleal commented 2 years ago

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)