cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_easy_cleanup modifies the stack???

From: Braden McDaniel <braden_at_endoframe.com>
Date: Sun, 31 Dec 2006 12:56:44 -0500

On Sun, 2006-12-31 at 14:47 +0100, Daniel Stenberg wrote:
> On Fri, 29 Dec 2006, Braden McDaniel wrote:
>
> > Can someone explain to me what's going on here? This code
> >
> > fprintf(stderr, "msg->easy_handle = %lu\n", ptrdiff_t(msg->easy_handle));
> > curl_easy_cleanup(msg->easy_handle);
> > fprintf(stderr, "msg->easy_handle = %lu\n", ptrdiff_t(msg->easy_handle));
> >
> > results in this output:
> >
> > msg->easy_handle = 10975264
> > msg->easy_handle = 9801088
>
> > Now, I know the docs for curl_easy_cleanup say that the handle isn't usable
> > after calling the function. But even so, this outcome really surprised me. I
> > just didn't expect a C function to behave this way.
>
> You used curl_mult_info_read() to get that 'msg' pointer, and it will point to
> memory that is kept in the CURL struct).
>
> When you call curl_easy_cleanup(), libcurl will free the memory msg points to,
> and thus you get this result. I'll clarify this somewhat better in the
> curl_multi_info_read() man page.

Aha; makes sense. Thanks.

-- 
Braden McDaniel                           e-mail: <braden_at_endoframe.com>
<http://endoframe.com>                    Jabber: <braden@jabber.org>
Received on 2006-12-31