cURL / Mailing Lists / curl-library / Single Mail

curl-library

Issues with curl_slist_append and curl_slist_free_all

From: John Barker <jb_at_optimiser.com>
Date: Mon, 28 Apr 2003 09:38:11 +0800

Folks,

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. Alternatively if I do

#define HEADER_ACCEPT "Accept: */*"

szHeader = strdup(HEADER_ACCEPT);
if(szHeader) {
    cslHeaders = curl_slist_append(NULL, szHeader);
}

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. Would it be possible to provide an additional function, say:
curl_slist_free_all_c which might look like this:

/* be nice and clean up resources using provided callback */
void curl_slist_free_all_c(struct curl_slist *list, void
(*freeheader)(void *))
{
  struct curl_slist *next;
  struct curl_slist *item;

  if (!list)
    return;

  item = list;
  do {
    next = item->next;
       
    if (item->data && freeheader) {
      freeheader(item->data);
    }
    free(item);
    item = next;
  } while (next);
}

This allows me provide headers to libcurl from the stack rather than
from the heap and solves issues with alternative memory allocation schemes.

Cheers,
JB

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2003-04-28