cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Crash in curl_easy_cleanup

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Tue, 2 Jan 2007 00:27:09 +0100 (CET)

On Sun, 31 Dec 2006, Braden McDaniel wrote:

> I have the following loop to see what transfers are complete:
>
> while ((msg = curl_multi_info_read(curl_source->multi_handle,
> &msgs_in_queue))) {
> if (msg->msg == CURLMSG_DONE) {
> curl_multi_remove_handle(curl_source->multi_handle,
> msg->easy_handle);

> const stream_data_map_t::size_type num_erased =
> callback_data->stream_data_map.erase(msg->easy_handle);

This is not done properly. The man page for curl_multi_info_read() explains
that the data it returns will not survive a call to
curl_multi_remove_handle().

You thus need to copy the data you need from the 'msg' struct before you call
curl_multi_remove_handle or curl_easy_cleanup.

> The documentation indicates that the easy handle is usable on its own after
> being removed from the multi handle;

It is.

> so presumably I need to call curl_easy_cleanup on it (right?). But if it's
> not safe to do that at this point, when is it safe to do?

It is safe to do, but with this setup you most likely passed in junk to
curl_easy_cleanup...

-- 
  Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
Received on 2007-01-02