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