From a4acb246d3993b32efc2c6b06cec2ef10a25d5b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20H=C3=A4rer?= Date: Sun, 19 Nov 2023 19:27:04 +0100 Subject: [PATCH] DllLibCurl: Cleanup sessions before cleaning up library Fixes memory leaks like this: Direct leak of 5416 byte(s) in 1 object(s) allocated from: #0 0x564b473d8ba1 in calloc (kodi-test+0xa2a8ba1) (BuildId: e17174d164cea5687c750d197e31e6bf0beb86ad) #1 0x7f6be8db88fa (/usr/lib/libcurl.so.4+0x708fa) (BuildId: b5fe52836b4db517485d04822e61ce49b2793833) #2 0x564b4fb89895 in XCURL::DllLibCurlGlobal::easy_acquire(char const*, char const*, void**, void**) xbmc/filesystem/DllLibCurl.cpp:208:22 #3 0x564b4facc484 in XFILE::CCurlFile::Open(CURL const&) xbmc/filesystem/CurlFile.cpp:1086:21 #4 0x564b4fac72a0 in XFILE::CCurlFile::Service(std::__cxx11::basic_string, std::allocator> const&, std::__cxx11::basic_string, std::allocator>&) xbmc/filesystem/CurlFile.cpp:966:7 #5 0x564b4fac7a69 in XFILE::CCurlFile::Get(std::__cxx11::basic_string, std::allocator> const&, std::__cxx11::basic_string, std::allocator>&) xbmc/filesystem/CurlFile.cpp:960:10 #6 0x564b47bbd6f6 in TestWebServer_CanGetCachedRangedFileWithExactIfRange_Test::TestBody() xbmc/network/test/TestWebServer.cpp:900:3 #7 0x7f6be969665b (/usr/lib/libgtest.so.1.14.0+0x5365b) (BuildId: d3f0da00423297c687edfdde9cb59f357b95e001) Indirect leak of 5416 byte(s) in 1 object(s) allocated from: #0 0x564b473d8ba1 in calloc (kodi-test+0xa2a8ba1) (BuildId: e17174d164cea5687c750d197e31e6bf0beb86ad) #1 0x7f6be8db88fa (/usr/lib/libcurl.so.4+0x708fa) (BuildId: b5fe52836b4db517485d04822e61ce49b2793833) Indirect leak of 5376 byte(s) in 2 object(s) allocated from: #0 0x564b473d8839 in malloc (kodi-test+0xa2a8839) (BuildId: e17174d164cea5687c750d197e31e6bf0beb86ad) #1 0x7f6be8d79a44 (/usr/lib/libcurl.so.4+0x31a44) (BuildId: b5fe52836b4db517485d04822e61ce49b2793833) [...] --- xbmc/filesystem/DllLibCurl.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xbmc/filesystem/DllLibCurl.cpp b/xbmc/filesystem/DllLibCurl.cpp index 8367e9d9d7796..c2c215a08e76c 100644 --- a/xbmc/filesystem/DllLibCurl.cpp +++ b/xbmc/filesystem/DllLibCurl.cpp @@ -123,6 +123,15 @@ DllLibCurlGlobal::DllLibCurlGlobal() DllLibCurlGlobal::~DllLibCurlGlobal() { + for (auto& session : m_sessions) + { + if (session.m_multi && session.m_easy) + multi_remove_handle(session.m_multi, session.m_easy); + if (session.m_easy) + easy_cleanup(session.m_easy); + if (session.m_multi) + multi_cleanup(session.m_multi); + } // close libcurl curl_global_cleanup(); }