curl_easy_cleanup(3)

πŸ’… curl_easy_cleanup(3) β€” the libcurl girlies' guide

so this is curl_easy_cleanup from the Library Functions Manual bestie, and it's literally the breakup song of the libcurl discography πŸŽ€


✨ NAME ✨

curl_easy_cleanup β€” free an easy handle πŸ¦‹


✨ SYNOPSIS ✨

#include <curl/curl.h>

void curl_easy_cleanup(CURL *handle);

✨ DESCRIPTION ✨

okay so picture this: this function is the literal opposite of curl_easy_init(3). It closes down and frees, like, all the resources that were previously associated with this easy handle. everything. gone. clean slate energy ✨

it closes all connections this handle has used and β€” this is the spicy part β€” possibly has kept open until now, unless the easy handle was attached to a multi handle while doing the transfers. πŸ‘€

🚨 bestie do NOT call this function if you intend to transfer more files. reusing handles is a key to good performance with libcurl, i'm not kidding, the way that reusing handles just makes everything faster, iykyk πŸ’…

occasionally you may get your progress callback or header callback called from within curl_easy_cleanup(3) β€” yeah, from the inside, messy 😭 β€” (if previously set for the handle using curl_easy_setopt(3)). like if libcurl decides to shut down the connection and the protocol is of a kind that requires a command/response sequence before disconnect. examples of such protocols are FTP, POP3 and IMAP. so don't be shocked when the callbacks show up to the party uninvited 🫢

Any use of the easy handle after this function has been called and have returned, is illegal. like not "oops my bad" illegal, fr fr illegal. πŸ’€

To close an easy handle that has been used with the multi interface, make sure to first call curl_multi_remove_handle(3) to remove it from the multi handle before it is closed. order matters, always has 🌸

Passing in a NULL pointer in handle makes this function return immediately with no action. mmm, a no-op, we love a graceful exit πŸ™ˆ


✨ PROTOCOLS ✨

This functionality affects all supported protocols πŸ‘‘ (yes, all of them, every single one, iconic)


✨ EXAMPLE ✨

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
    result = curl_easy_perform(curl);
    if(result)
      printf("error: %s\n", curl_easy_strerror(result));
    curl_easy_cleanup(curl);
  }
}

look at that β€” init, setopt, perform, error check, cleanup. the whole little lifecycle, so satisfying, it's giving main character energy ⭐


✨ AVAILABILITY ✨

Added in curl 7.1 🌈 (she's been here a while, a real veteran πŸ’œ)


✨ RETURN VALUE ✨

None β€” returns nothing, gives nothing, just vibes and cleanup 🧚


✨ SEE ALSO ✨


that's the whole page bestie, go free those handles responsibly 🫢

<div>β€” from the libcurl girlies, dated 2026-10-12, page curl_easy_cleanup(3), slay βœ¨πŸ’–</div>

πŸ“¦ where this page comes from