cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_easy_cleanup with curl_multi_info_read

From: codemastr <codemstr_at_ptd.net>
Date: Thu, 19 Feb 2004 16:55:03 -0500

>
> The memory used for the struct that curl_multi_info_read() returns is
> allocated per easy-handle in the multi-handle.
>
> That means the struct will be freed when you call
curl_multi_remove_handle()
> or curl_multi_cleanup().
>
> Does this answer your question?
Not exactly. Let me provide my code. One of my users is reporting a random
crash (I assume memory problems) when I call curl_easy_cleanup() as
described in my first mail. This most likely is a problem with my code, not
libcurl. The problem is however that there really isn't very good examples
available for the multi interface so I could be doing it wrong.

[...]

 while ((msg = curl_multi_info_read(multihandle, &msgs_left))) {
  if (msg->msg == CURLMSG_DONE)
  {
   FileHandle *handle; // CURLINFO_PRIVATE result variable
   char *url;
   long code;
   long last_mod;

   if (msg->data.result == CURLE_OK)
        handle->callback(url, handle->filename, NULL, 0);
   free(handle); // Release the private data that I previously allocated
   curl_easy_cleanup(msg->easy_handle);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ That's where the problem occurs
  }
 }
}

My guess is libcurl doesn't like that I'm cleaning up the easy handle from
within the curl_multi_info_read loop. Am I correct in this assumption? If I
changed that to be:

curl_multi_remove_handle(multihandle, msg->easy_handle);
curl_easy_cleanup(msg->easy_handle);

Would that be correct? If not, can you point out what I must do to make sure
I don't screw up libcurl's memory?

Thanks,
Dominick Meglio
Received on 2004-02-19