diff -ru curl-7.10.6.orig/lib/easy.c curl-7.10.6/lib/easy.c
--- curl-7.10.6.orig/lib/easy.c	Fri Jul 25 10:30:58 2003
+++ curl-7.10.6/lib/easy.c	Sun Aug  3 13:01:11 2003
@@ -76,6 +76,7 @@
 #include "url.h"
 #include "getinfo.h"
 #include "hostip.h"
+#include "share.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #include <curl/mprintf.h>
@@ -233,15 +234,19 @@
 {
   struct SessionHandle *data = (struct SessionHandle *)curl;
 
-  if (Curl_global_host_cache_use(data) && data->hostcache != Curl_global_host_cache_get()) {
-    if (data->hostcache) {
-      Curl_hash_destroy(data->hostcache);
+  if ( ! (data->share && data->share->hostcache) ) {
+
+    if (Curl_global_host_cache_use(data) && data->hostcache != Curl_global_host_cache_get()) {
+      if (data->hostcache) {
+        Curl_hash_destroy(data->hostcache);
+      }
+      data->hostcache = Curl_global_host_cache_get();
+    }
+
+    if (!data->hostcache) {
+      data->hostcache = Curl_hash_alloc(7, Curl_freednsinfo);
     }
-    data->hostcache = Curl_global_host_cache_get();
-  }
 
-  if (!data->hostcache) {
-    data->hostcache = Curl_hash_alloc(7, Curl_freednsinfo);
   }
   
   return Curl_perform(data);
@@ -250,8 +255,10 @@
 void curl_easy_cleanup(CURL *curl)
 {
   struct SessionHandle *data = (struct SessionHandle *)curl;
-  if (!Curl_global_host_cache_use(data)) {
-    Curl_hash_destroy(data->hostcache);
+  if ( ! (data->share && data->share->hostcache) ) {
+    if ( !Curl_global_host_cache_use(data)) {
+      Curl_hash_destroy(data->hostcache);
+    }
   }
   Curl_close(data);
 }
diff -ru curl-7.10.6.orig/lib/http.c curl-7.10.6/lib/http.c
--- curl-7.10.6.orig/lib/http.c	Mon Jul 28 12:21:57 2003
+++ curl-7.10.6/lib/http.c	Sun Aug  3 13:02:31 2003
@@ -846,10 +846,12 @@
   }
 
   if(data->cookies) {
+    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
     co = Curl_cookie_getlist(data->cookies,
                              conn->allocptr.cookiehost?
                              conn->allocptr.cookiehost:host, ppath,
                              (bool)(conn->protocol&PROT_HTTPS?TRUE:FALSE));
+    Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
   }
 
   if (conn->bits.httpproxy &&
diff -ru curl-7.10.6.orig/lib/share.c curl-7.10.6/lib/share.c
--- curl-7.10.6.orig/lib/share.c	Thu Jun 26 13:28:26 2003
+++ curl-7.10.6/lib/share.c	Sun Aug  3 13:15:40 2003
@@ -76,6 +76,9 @@
         break;
 
       case CURL_LOCK_DATA_COOKIE:
+        if (!share->cookies) {
+          share->cookies = Curl_cookie_init( NULL, NULL, TRUE );
+        }
         break;
 
       case CURL_LOCK_DATA_SSL_SESSION:
@@ -103,6 +106,10 @@
         break;
 
       case CURL_LOCK_DATA_COOKIE:
+        if (share->cookies) {
+          Curl_cookie_cleanup(share->cookies);
+          share->cookies = NULL;
+        }
         break;
 
       case CURL_LOCK_DATA_SSL_SESSION:
diff -ru curl-7.10.6.orig/lib/share.h curl-7.10.6/lib/share.h
--- curl-7.10.6.orig/lib/share.h	Wed Feb  5 08:05:11 2003
+++ curl-7.10.6/lib/share.h	Fri Aug  1 22:18:02 2003
@@ -26,6 +26,7 @@
 
 #include "setup.h"
 #include <curl/curl.h>
+#include "cookie.h"
 
 /* this struct is libcurl-private, don't export details */
 struct Curl_share {
@@ -37,6 +38,7 @@
   void *clientdata;
 
   curl_hash *hostcache;
+  struct CookieInfo *cookies;
 };
 
 CURLSHcode Curl_share_lock (
diff -ru curl-7.10.6.orig/lib/transfer.c curl-7.10.6/lib/transfer.c
--- curl-7.10.6.orig/lib/transfer.c	Fri Jul 25 10:30:58 2003
+++ curl-7.10.6/lib/transfer.c	Sun Aug  3 13:15:39 2003
@@ -707,12 +707,14 @@
             }
             else if(data->cookies &&
                     checkprefix("Set-Cookie:", k->p)) {
+              Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
               Curl_cookie_add(data->cookies, TRUE, k->p+11,
                               /* If there is a custom-set Host: name, use it
                                  here, or else use real peer host name. */
                               conn->allocptr.cookiehost?
                               conn->allocptr.cookiehost:conn->name,
                               conn->ppath);
+              Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
             }
             else if(checkprefix("Last-Modified:", k->p) &&
                     (data->set.timecondition || data->set.get_filetime) ) {
@@ -1509,12 +1511,14 @@
      do it now! */
   if(data->change.cookielist) {
     struct curl_slist *list = data->change.cookielist;
+    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
     while(list) {
       data->cookies = Curl_cookie_init(list->data,
                                        data->cookies,
                                        data->set.cookiesession);
       list = list->next;
     }
+    Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
     curl_slist_free_all(data->change.cookielist); /* clean up list */
     data->change.cookielist = NULL; /* don't do this again! */
   }
diff -ru curl-7.10.6.orig/lib/url.c curl-7.10.6/lib/url.c
--- curl-7.10.6.orig/lib/url.c	Fri Jul 25 10:30:58 2003
+++ curl-7.10.6/lib/url.c	Sun Aug  3 13:15:39 2003
@@ -191,10 +191,6 @@
   Curl_SSL_Close_All(data);
 #endif
 
-  /* No longer a dirty share, if it exists */
-  if (data->share)
-    data->share->dirty--;
-
   if(data->change.cookielist) /* clean up list if any */
     curl_slist_free_all(data->change.cookielist);
 
@@ -213,13 +209,17 @@
   Curl_safefree(data->state.headerbuff);
 
 #ifndef CURL_DISABLE_HTTP
+  Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
   if(data->set.cookiejar) {
     /* we have a "destination" for all the cookies to get dumped to */
     if(Curl_cookie_output(data->cookies, data->set.cookiejar))
       infof(data, "WARNING: failed to save cookies in given jar\n");
   }
 
-  Curl_cookie_cleanup(data->cookies);
+  if( !data->share || (data->cookies != data->share->cookies) ) {
+    Curl_cookie_cleanup(data->cookies);
+  }
+  Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
 #endif
 
   /* free the connection cache */
@@ -229,6 +229,10 @@
 
   Curl_digest_cleanup(data);
 
+  /* No longer a dirty share, if it exists */
+  if (data->share)
+    data->share->dirty--;
+
   free(data);
   return CURLE_OK;
 }
@@ -1148,34 +1152,69 @@
     {
       struct Curl_share *set;
       set = va_arg(param, struct Curl_share *);
+
+      /* disconnect from old share, if any */
       if(data->share)
       {
         Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
 
-        /* checking the dns cache stuff */
         if(data->share->hostcache == data->hostcache)
         {
           data->hostcache = NULL;
         }
 
+        if(data->share->cookies == data->cookies)
+        {
+          data->cookies = NULL;
+        }
+
         data->share->dirty--;
 
         Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
+        data->share = NULL;
       }
 
+      /* use new share if it set */
       data->share = set;
+      if(data->share)
+      {
 
-      Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
+        Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
 
-      data->share->dirty++;
+        data->share->dirty++;
 
-      if( data->hostcache )
-      {
-        Curl_hash_destroy(data->hostcache);
-        data->hostcache = data->share->hostcache;
+        if(data->share->hostcache)
+        {
+          /* use shared host cache, first free own one if any */
+          if(data->hostcache)
+          {
+            Curl_hash_destroy(data->hostcache);
+          }
+          data->hostcache = data->share->hostcache;
+
+        }
+        
+        if(data->share->cookies)
+        {
+          /* use shared cookie list, first free own one if any */
+          if (data->cookies)
+            Curl_cookie_cleanup(data->cookies);
+          data->cookies = data->share->cookies;
+        }
+
+        Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
+        
       }
 
-      Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
+      /* check cookie list is set */
+      if(!data->cookies)
+      {
+        data->cookies = Curl_cookie_init( NULL, NULL, TRUE );
+      }
+      
+      /* check for host cache not needed,
+       * it will be done by curl_easy_perform */
+ 
     }
     break;
 

