Coverage Report

Created: 2026-09-14 07:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl_fuzzer/proto_fuzzer/curl_raii.h
Line
Count
Source
1
/*
2
 * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al.
3
 *
4
 * SPDX-License-Identifier: curl
5
 */
6
7
/// @file
8
/// @brief Common ownership types for independently cleaned-up curl handles.
9
10
#ifndef PROTO_FUZZER_CURL_RAII_H_
11
#define PROTO_FUZZER_CURL_RAII_H_
12
13
#include <curl/curl.h>
14
15
#include <memory>
16
17
namespace proto_fuzzer {
18
19
/// @brief Destroy an independently owned easy handle.
20
struct CurlEasyDeleter {
21
  /// Release an easy handle through libcurl's matching cleanup API.
22
  /// @param easy Handle owned by the invoking smart pointer.
23
326k
  void operator()(CURL* easy) const noexcept {
24
326k
    if (easy != nullptr) {
25
326k
      curl_easy_cleanup(easy);
26
326k
    }
27
326k
  }
28
};
29
30
/// @brief Destroy an independently owned multi handle.
31
struct CurlMultiDeleter {
32
  /// Release a multi handle through libcurl's matching cleanup API.
33
  /// @param multi Handle owned by the invoking smart pointer.
34
284k
  void operator()(CURLM* multi) const noexcept {
35
284k
    if (multi != nullptr) {
36
284k
      (void)curl_multi_cleanup(multi);
37
284k
    }
38
284k
  }
39
};
40
41
/// @brief Destroy a caller-owned curl_slist.
42
struct CurlSlistDeleter {
43
  /// Release a complete caller-owned linked list.
44
  /// @param list List owned by the invoking smart pointer.
45
328k
  void operator()(curl_slist* list) const noexcept { curl_slist_free_all(list); }
46
};
47
48
/// Unique ownership of a CURL easy handle.
49
using CurlEasyPtr = std::unique_ptr<CURL, CurlEasyDeleter>;
50
/// Unique ownership of a CURL multi handle.
51
using CurlMultiPtr = std::unique_ptr<CURLM, CurlMultiDeleter>;
52
/// Unique ownership of a caller-owned curl_slist.
53
using CurlSlistPtr = std::unique_ptr<curl_slist, CurlSlistDeleter>;
54
55
}  // namespace proto_fuzzer
56
57
#endif  // PROTO_FUZZER_CURL_RAII_H_