15#include "proto_fuzzer/allocation_fault_injection.h"
17namespace proto_fuzzer {
27 : cleanup_(cleanup !=
nullptr ? cleanup : &curl_global_cleanup) {
30 (void)setenv(
"SSLKEYLOGFILE",
"/dev/null", 0);
34 std::signal(SIGPIPE, SIG_IGN);
36 const bool callbacks_active = allocation_fault_injection::InitializeCurl();
37 if (allocation_fault_injection::ClaimCurlInitializationReference()) {
38 ++initialization_count_;
40 if (!callbacks_active) {
41 std::fputs(
"warning: libcurl allocation fault injection is unavailable\n", stderr);
43 if (initialization_count_ == 0 && curl_global_init(CURL_GLOBAL_ALL) == CURLE_OK) {
44 ++initialization_count_;
46 initialized_ = initialization_count_ != 0;
47 next_registered_ = registered_lifecycles;
48 registered_lifecycles =
this;
51CurlGlobalLifecycle::~CurlGlobalLifecycle() {
54 while (*link !=
nullptr && *link !=
this) {
55 link = &(*link)->next_registered_;
58 *link = next_registered_;
60 next_registered_ =
nullptr;
68 allocation_fault_injection::Reset();
69 while (initialization_count_ != 0) {
71 --initialization_count_;
79 lifecycle = lifecycle->next_registered_) {
80 lifecycle->FinalizeForProcessExit();
Own the proto runtime's one curl global initialization.
void(*)() CleanupFunction
Process-exit cleanup callback, injectable for lifecycle regression tests.
CurlGlobalLifecycle(CleanupFunction cleanup=nullptr) noexcept
Initialize curl and its allocation hooks for this process.
void FinalizeForProcessExit() noexcept
Release this object's references after the fuzz engine has stopped.
friend void FinalizeRegisteredCurlGlobalLifecyclesForExit() noexcept
Finalize all registered process lifecycles before static destruction.
Process-wide libcurl initialization and final cleanup.