diff --git a/lib/cookie.c b/lib/cookie.c
index 697081117da765e497c4d13b5b085c5fb6b0a908..9ffdd2abe3a6d77643d3a3082238656466ffd077 100644
--- a/lib/cookie.c
+++ b/lib/cookie.c
@@ -377,8 +377,15 @@ Curl_cookie_add(struct CookieInfo *c,
 
         free(co);   /* free the newly alloced memory */
         co = clist; /* point to the previous struct instead */
-      }
 
+        /* We have replaced a cookie, now skip the rest of the list but
+           make sure the 'lastc' pointer is properly set */
+        do {
+          lastc = clist;
+          clist = clist->next;
+        } while(clist);
+        break;
+      }
     }
     lastc = clist;
     clist = clist->next;