curl_formfree(3)

πŸ’… curl_formfree(3) β€” free a previously build multipart form post chain

ok so real talk bestie, this is a page from the libcurl Library Functions Manual (yes, that libcurl, the one you've been linking against since forever 🫢), and it's about tidying up after yourself. Let's get into it.


✨ SYNOPSIS ✨

#include <curl/curl.h>

void curl_formfree(struct curl_httppost *form);

that's the whole vibe. one include, one function, zero drama πŸ’…


🌸 DESCRIPTION 🌸

okay so first things first, and I need you to hear me on this one:

This function is deprecated. Do not use. 🚨 See curl_mime_init(3) instead. like, genuinely, go look at that one.

curl_formfree() is the little cleanup crew 🧹 for data you previously built/appended with curl_formadd(3). You must call it when the data has been used β€” and "used" typically means after curl_easy_perform(3) has been called. it's giving "return the shopping cart" energy, ngl.

the pointer you free is the same pointer you passed to the CURLOPT_HTTPPOST(3) option, which is the firstitem pointer from the curl_formadd(3) invoke(s). same one, no copies, iykyk.

form is the pointer as returned from a previous call to curl_formadd(3) and may be NULL.

and if you pass in a NULL pointer in form? the function returns immediately with no action. literally just πŸ‘€ and leaves. no crash, no fuss. iconic behaviour honestly.


🌈 PROTOCOLS 🌈

this functionality affects http only. that's the whole list. http girlies only πŸ’–


πŸ¦‹ EXAMPLE πŸ¦‹

here's the whole thing in action, bestie β€” copy it exactly:

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    struct curl_httppost *formpost;
    struct curl_httppost *lastptr;

    /* Fill in a file upload field */
    curl_formadd(&formpost,
                 &lastptr,
                 CURLFORM_COPYNAME, "file",
                 CURLFORM_FILE, "nice-image.jpg",
                 CURLFORM_END);

    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);

    curl_easy_perform(curl);

    /* then cleanup the formpost chain */
    curl_formfree(formpost);
  }
}

see how formpost goes into curl_formadd, then into CURLOPT_HTTPPOST, then finally into curl_formfree? that's the full circle moment πŸ”₯ main character energy from start to finish.


πŸ’€ DEPRECATED πŸ’€

Deprecated in 7.56.0. so yeah. it's a legacy era. respect the history, but move on πŸŽ€


⭐ AVAILABILITY ⭐

Added in curl 7.1. ancient. vintage. a true elder of the library πŸ‘‘


πŸŽ€ RETURN VALUE πŸŽ€

None. that's it. nothing comes back. empty handed but at peace 🧚


πŸ’œ SEE ALSO πŸ’œ


k that's the page!! stay safe, free your formposts, and please please please use the curl_mime_* family instead πŸ’–

β€” with love, from the libcurl manual, dated 2026-10-12 πŸ¦‹βœ¨

πŸ“¦ where this page comes from