curl_slist_free_all(3)

✨ curl_slist_free_all(3) ✨

okay so bestie, this one's from the Library Functions Manual and it's lowkey the ✨cleanup queen✨ of the curl_slist world. Let's get into it πŸ’…


🌸 NAME 🌸

curl_slist_free_all β€” free an entire curl_slist list πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <curl/curl.h>

void curl_slist_free_all(struct curl_slist *list);

πŸ’– DESCRIPTION πŸ’–

curl_slist_free_all() removes all traces of a previously built curl_slist linked list. like, it's giving full demolition, no crumbs left behind πŸ’€βœ¨

Passing in a NULL pointer in list makes this function return immediately with no action. so if you're like "hmm is my list even real," passing NULL is totally fine, it just shrugs and leaves 🫢

Any use of the list after this function has been called and have returned, is illegal. 😭 like fr fr, do NOT touch it afterwards. it's gone. periodt.

🌈 PROTOCOLS 🌈

This functionality affects all supported protocols πŸ‘‘ every single one, no cap.


πŸŽ€ EXAMPLE πŸŽ€

int main(void)
{
  CURL *handle = curl_easy_init();
  struct curl_slist *slist = NULL;

  slist = curl_slist_append(slist, "X-libcurl: coolness");

  if(!slist)
    return -1;

  curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);

  curl_easy_perform(handle);

  curl_slist_free_all(slist); /* free the list again */
}

see how she builds the list, uses it, and then frees the list again? that's the main character energy we love to see πŸ’…βœ¨


⭐ AVAILABILITY ⭐

Added in curl 7.1 β€” an icon from way back, she's been slaying since forever 🧚


πŸ”₯ RETURN VALUE πŸ”₯

Nothing. literally nothing, it just does the thing and dips πŸ™ˆ


πŸ¦‹ SEE ALSO πŸ¦‹


libcurl πŸŽ€ 2026-10-12 πŸŽ€ curl_slist_free_all(3) β€” okay that's the whole page, go forth and free your lists responsibly bestie, mwah πŸ«ΆπŸ’–

πŸ“¦ where this page comes from