xref: /curl/docs/libcurl/curl_easy_cleanup.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_easy_cleanup
5Section: 3
6Source: libcurl
7See-also:
8  - curl_easy_duphandle (3)
9  - curl_easy_init (3)
10  - curl_easy_reset (3)
11  - curl_multi_cleanup (3)
12  - curl_multi_remove_handle (3)
13Protocol:
14  - All
15Added-in: 7.1
16---
17
18# NAME
19
20curl_easy_cleanup - free an easy handle
21
22# SYNOPSIS
23
24~~~c
25#include <curl/curl.h>
26
27void curl_easy_cleanup(CURL *handle);
28~~~
29
30# DESCRIPTION
31
32This function is the opposite of curl_easy_init(3). It closes down and frees
33all resources previously associated with this easy handle.
34
35This call closes all connections this handle has used and possibly has kept
36open until now unless the easy handle was attached to a multi handle while
37doing the transfers. Do not call this function if you intend to transfer more
38files, reusing handles is a key to good performance with libcurl.
39
40Occasionally you may get your progress callback or header callback called from
41within curl_easy_cleanup(3) (if previously set for the handle using
42curl_easy_setopt(3)). Like if libcurl decides to shut down the connection and
43the protocol is of a kind that requires a command/response sequence before
44disconnect. Examples of such protocols are FTP, POP3 and IMAP.
45
46Any use of the easy **handle** after this function has been called and have
47returned, is illegal.
48
49To close an easy handle that has been used with the multi interface, make sure
50to first call curl_multi_remove_handle(3) to remove it from the multi handle
51before it is closed.
52
53Passing in a NULL pointer in *handle* makes this function return immediately
54with no action.
55
56# %PROTOCOLS%
57
58# EXAMPLE
59
60~~~c
61int main(void)
62{
63  CURL *curl = curl_easy_init();
64  if(curl) {
65    CURLcode res;
66    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
67    res = curl_easy_perform(curl);
68    if(res)
69      printf("error: %s\n", curl_easy_strerror(res));
70    curl_easy_cleanup(curl);
71  }
72}
73~~~
74
75# %AVAILABILITY%
76
77# RETURN VALUE
78
79None
80