From bae713be2e51faa5cbe0ac4bcd21c0a3ee72ff8e Mon Sep 17 00:00:00 2001 From: Jason Jeremy Iman Date: Wed, 25 Jan 2023 13:28:31 +0900 Subject: [PATCH] LibcurlWrapper uses curl_global_cleanup LibcurlWrapper is missing a curl_global_cleanup causing a memory leak. The curl_global_init is called automatically when calling curl_easy_init without first doing curl_global_init. BUG=chromium:1405410 TEST=units with asan Change-Id: I4982fd5265b0df91076ed428f1134a681a7f28c6 Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/4189295 Reviewed-by: Joshua Peraza --- src/common/linux/libcurl_wrapper.cc | 5 +++++ src/common/linux/libcurl_wrapper.h | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/common/linux/libcurl_wrapper.cc b/src/common/linux/libcurl_wrapper.cc index 09668161..a53087d9 100644 --- a/src/common/linux/libcurl_wrapper.cc +++ b/src/common/linux/libcurl_wrapper.cc @@ -47,6 +47,7 @@ LibcurlWrapper::LibcurlWrapper() LibcurlWrapper::~LibcurlWrapper() { if (init_ok_) { (*easy_cleanup_)(curl_); + (*global_cleanup_)(); dlclose(curl_lib_); } } @@ -262,6 +263,10 @@ bool LibcurlWrapper::SetFunctionPointers() { SET_AND_CHECK_FUNCTION_POINTER(formfree_, "curl_formfree", void(*)(curl_httppost*)); + + SET_AND_CHECK_FUNCTION_POINTER(global_cleanup_, + "curl_global_cleanup", + void(*)(void)); return true; } diff --git a/src/common/linux/libcurl_wrapper.h b/src/common/linux/libcurl_wrapper.h index f4a4dca4..f8f961c1 100644 --- a/src/common/linux/libcurl_wrapper.h +++ b/src/common/linux/libcurl_wrapper.h @@ -39,6 +39,9 @@ #include "third_party/curl/curl.h" namespace google_breakpad { + +// This class is only safe to be used on single-threaded code because of its +// usage of libcurl's curl_global_cleanup(). class LibcurlWrapper { public: LibcurlWrapper(); @@ -111,6 +114,7 @@ class LibcurlWrapper { CURLcode (*easy_getinfo_)(CURL*, CURLINFO info, ...); void (*easy_reset_)(CURL*); void (*formfree_)(struct curl_httppost*); + void (*global_cleanup_)(void); }; }