Coverage Report

Created: 2026-10-15 06:25

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
393k
  void operator()(CURL* easy) const noexcept {
24
393k
    if (easy != nullptr) {
25
393k
      curl_easy_cleanup(easy);
26
393k
    }
27
393k
  }
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
344k
  void operator()(CURLM* multi) const noexcept {
35
344k
    if (multi != nullptr) {
36
344k
      (void)curl_multi_cleanup(multi);
37
344k
    }
38
344k
  }
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
454k
  void operator()(curl_slist* list) const noexcept { curl_slist_free_all(list); }
46
};
47
48
/// @brief Destroy a caller-owned MIME tree, including transferred children.
49
struct CurlMimeDeleter {
50
  /// Release a complete MIME tree through libcurl's matching cleanup API.
51
  /// @param mime MIME root owned by the invoking smart pointer.
52
47.8k
  void operator()(curl_mime* mime) const noexcept { curl_mime_free(mime); }
53
};
54
55
/// Unique ownership of a CURL easy handle.
56
using CurlEasyPtr = std::unique_ptr<CURL, CurlEasyDeleter>;
57
/// Unique ownership of a CURL multi handle.
58
using CurlMultiPtr = std::unique_ptr<CURLM, CurlMultiDeleter>;
59
/// Unique ownership of a caller-owned curl_slist.
60
using CurlSlistPtr = std::unique_ptr<curl_slist, CurlSlistDeleter>;
61
/// Unique ownership of a caller-owned curl_mime tree.
62
using CurlMimePtr = std::unique_ptr<curl_mime, CurlMimeDeleter>;
63
64
}  // namespace proto_fuzzer
65
66
#endif  // PROTO_FUZZER_CURL_RAII_H_