Coverage Report

Created: 2026-12-01 06:33

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
491k
  void operator()(CURL* easy) const noexcept {
24
491k
    if (easy != nullptr) {
25
491k
      curl_easy_cleanup(easy);
26
491k
    }
27
491k
  }
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
430k
  void operator()(CURLM* multi) const noexcept {
35
430k
    if (multi != nullptr) {
36
430k
      (void)curl_multi_cleanup(multi);
37
430k
    }
38
430k
  }
39
};
40
41
/// @brief Destroy an independently owned share handle.
42
struct CurlShareDeleter {
43
  /// Release a share handle through libcurl's matching cleanup API.
44
  /// @param share Handle owned by the invoking smart pointer.
45
27.0k
  void operator()(CURLSH* share) const noexcept {
46
27.0k
    if (share != nullptr) {
47
27.0k
      (void)curl_share_cleanup(share);
48
27.0k
    }
49
27.0k
  }
50
};
51
52
/// @brief Destroy a caller-owned curl_slist.
53
struct CurlSlistDeleter {
54
  /// Release a complete caller-owned linked list.
55
  /// @param list List owned by the invoking smart pointer.
56
576k
  void operator()(curl_slist* list) const noexcept { curl_slist_free_all(list); }
57
};
58
59
/// @brief Destroy a caller-owned MIME tree, including transferred children.
60
struct CurlMimeDeleter {
61
  /// Release a complete MIME tree through libcurl's matching cleanup API.
62
  /// @param mime MIME root owned by the invoking smart pointer.
63
81.6k
  void operator()(curl_mime* mime) const noexcept { curl_mime_free(mime); }
64
};
65
66
/// Unique ownership of a CURL easy handle.
67
using CurlEasyPtr = std::unique_ptr<CURL, CurlEasyDeleter>;
68
/// Unique ownership of a CURL multi handle.
69
using CurlMultiPtr = std::unique_ptr<CURLM, CurlMultiDeleter>;
70
/// Unique ownership of a CURL share handle.
71
using CurlSharePtr = std::unique_ptr<CURLSH, CurlShareDeleter>;
72
/// Unique ownership of a caller-owned curl_slist.
73
using CurlSlistPtr = std::unique_ptr<curl_slist, CurlSlistDeleter>;
74
/// Unique ownership of a caller-owned curl_mime tree.
75
using CurlMimePtr = std::unique_ptr<curl_mime, CurlMimeDeleter>;
76
77
}  // namespace proto_fuzzer
78
79
#endif  // PROTO_FUZZER_CURL_RAII_H_