cURL / Mailing Lists / curl-library / Single Mail


RE: CURLOPT_HTTPPOST documentation wrong?

From: Patrick Monnerat <>
Date: Tue, 15 Mar 2011 13:27:38 +0100 wrote:

> curl_easy_setopt ( curlhandle , CURLOPT_HTTPPOST , formptr ) ;
curl_easy_perform ( curlhandle ) ; curl_formfree ( formptr ) ;

> Now, the manual entry for CURLOPT_HTTPPOST says that the form data
should persist until the handle is released. Is this a mistake? It
seems logical to me that the data can be got rid of after the POST is
performed. I am reusing the one handle to do all my HTTP functions.
> My project ( a Wikipedia bot ) can run for days re-using the same curl
handle but the form data is always destroyed right after I get the
server's reply.

This is probably OK because you issue a new
curl_easy_setopt(CURLOPT_HTTPPOST) with a newly allocated pointer before
reusing the handle.
However, from a purist point of view, the code you show us leaves a
dangling pointer to the (released) form data attached to the handle.
If a subsequent curl_easy_perform() call were done for the same handle
without re-setting CURLOPT_HTTPPOST, data that do not exist anymore will
be accessed: this explicits what is clumsily, although properly
mentionned in the documentation.

To be "academic", I would change your code as follows:

curl_easy_setopt(curlhandle, CURLOPT_HTTPPOST, formptr);
curl_easy_setopt(curlhandle, CURLOPT_HTTPPOST, NULL); /* Avoid keeping
a dangling pointer. */

List admin:
Received on 2011-03-15