Index: lib/cookie.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/cookie.c,v
retrieving revision 1.85
diff -u -r1.85 cookie.c
--- lib/cookie.c	7 Nov 2007 09:21:35 -0000	1.85
+++ lib/cookie.c	23 Jan 2008 22:18:04 -0000
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -812,7 +812,7 @@
 void Curl_cookie_clearall(struct CookieInfo *cookies)
 {
   if(cookies) {
-    Curl_cookie_freelist(cookies->cookies);
+    Curl_cookie_freelist(cookies->cookies, TRUE);
     cookies->cookies = NULL;
     cookies->numcookies = 0;
   }
@@ -824,16 +824,22 @@
  *
  * Free a list of cookies previously returned by Curl_cookie_getlist();
  *
+ * The 'cookiestoo' argument tells this function whether to just free the
+ * list or actually also free all cookies within the list as well.
+ *
  ****************************************************************************/
 
-void Curl_cookie_freelist(struct Cookie *co)
+void Curl_cookie_freelist(struct Cookie *co, bool cookiestoo)
 {
   struct Cookie *next;
   if(co) {
     while(co) {
       next = co->next;
-      free(co); /* we only free the struct since the "members" are all
-                      just copied! */
+      if(cookiestoo)
+        freecookie(co);
+      else
+        free(co); /* we only free the struct since the "members" are all just
+                     pointed out in the main cookie list! */
       co = next;
     }
   }
@@ -867,7 +873,7 @@
       else
         prev->next = next;
 
-      free(curr);
+      freecookie(curr);
       cookies->numcookies--;
     }
     else
Index: lib/cookie.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/cookie.h,v
retrieving revision 1.25
diff -u -r1.25 cookie.h
--- lib/cookie.h	29 Aug 2007 05:36:53 -0000	1.25
+++ lib/cookie.h	23 Jan 2008 22:18:04 -0000
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -91,7 +91,7 @@
                                     const char *, struct CookieInfo *, bool);
 struct Cookie *Curl_cookie_getlist(struct CookieInfo *, const char *,
 		                   const char *, bool);
-void Curl_cookie_freelist(struct Cookie *);
+void Curl_cookie_freelist(struct Cookie *cookies, bool cookiestoo);
 void Curl_cookie_clearall(struct CookieInfo *cookies);
 void Curl_cookie_clearsess(struct CookieInfo *cookies);
 void Curl_cookie_cleanup(struct CookieInfo *);
Index: lib/http.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/http.c,v
retrieving revision 1.357
diff -u -r1.357 http.c
--- lib/http.c	14 Jan 2008 22:02:15 -0000	1.357
+++ lib/http.c	23 Jan 2008 22:18:05 -0000
@@ -2374,7 +2374,7 @@
           }
           co = co->next; /* next cookie please */
         }
-        Curl_cookie_freelist(store); /* free the cookie list */
+        Curl_cookie_freelist(store, FALSE); /* free the cookie list */
       }
       if(addcookies && (CURLE_OK == result)) {
         if(!count)
