curl-library
Re: Issues with curl_slist_append and curl_slist_free_all
Date: Mon, 28 Apr 2003 16:04:28 +0200 (CEST)
On Mon, 28 Apr 2003, John Barker wrote:
> I'm having some issues with using curl_slist_append and
> curl_slist_free_all. Firstly I'm trying to use curl_slist_append like so:
>
> #define HEADER_ACCEPT "Accept: */*"
>
> cslHeaders = curl_slist_append(NULL, HEADER_ACCEPT);
>
> Then as soon as I do curl_slist_free_all I find that the header is trying
> to be freed and my program crashes.
Yes, *free_all() does indeed attemp to free the header. How can that be
wrong?
> Alternatively if I do
>
> #define HEADER_ACCEPT "Accept: */*"
>
> szHeader = strdup(HEADER_ACCEPT);
> if(szHeader) {
> cslHeaders = curl_slist_append(NULL, szHeader);
> }
This will merely cause you to get a memory leak. curl_slist_append()
strdup()s the header by itself.
> When calling curl_slist_free_all I get access violations, my program is
> using a different method of memory allocation to that used by libcurl it
> seems.
In this case, libcurl will do both the malloc() and the free(). It really
wouldn't matter if you use a different one.
I can't understand how you get problems with these function calls.
Besides, if you're unhappy with the function calls to builds curl_slist
lists, you don't need them. You can make those linked-lists yourself!
-- Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs. ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sfReceived on 2003-04-28