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 <jperaza@chromium.org>
This commit is contained in:
Jason Jeremy Iman 2023-01-25 13:28:31 +09:00 committed by Joshua Peraza
parent 236743ed04
commit bae713be2e
2 changed files with 9 additions and 0 deletions

View file

@ -47,6 +47,7 @@ LibcurlWrapper::LibcurlWrapper()
LibcurlWrapper::~LibcurlWrapper() { LibcurlWrapper::~LibcurlWrapper() {
if (init_ok_) { if (init_ok_) {
(*easy_cleanup_)(curl_); (*easy_cleanup_)(curl_);
(*global_cleanup_)();
dlclose(curl_lib_); dlclose(curl_lib_);
} }
} }
@ -262,6 +263,10 @@ bool LibcurlWrapper::SetFunctionPointers() {
SET_AND_CHECK_FUNCTION_POINTER(formfree_, SET_AND_CHECK_FUNCTION_POINTER(formfree_,
"curl_formfree", "curl_formfree",
void(*)(curl_httppost*)); void(*)(curl_httppost*));
SET_AND_CHECK_FUNCTION_POINTER(global_cleanup_,
"curl_global_cleanup",
void(*)(void));
return true; return true;
} }

View file

@ -39,6 +39,9 @@
#include "third_party/curl/curl.h" #include "third_party/curl/curl.h"
namespace google_breakpad { 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 { class LibcurlWrapper {
public: public:
LibcurlWrapper(); LibcurlWrapper();
@ -111,6 +114,7 @@ class LibcurlWrapper {
CURLcode (*easy_getinfo_)(CURL*, CURLINFO info, ...); CURLcode (*easy_getinfo_)(CURL*, CURLINFO info, ...);
void (*easy_reset_)(CURL*); void (*easy_reset_)(CURL*);
void (*formfree_)(struct curl_httppost*); void (*formfree_)(struct curl_httppost*);
void (*global_cleanup_)(void);
}; };
} }