Skip to content

Commit

Permalink
cookie: avoid mutex deadlock
Browse files Browse the repository at this point in the history
... by removing the extra mutex locks around th call to
Curl_flush_cookies() which takes care of the locking itself already.

Bug: http://curl.haxx.se/mail/lib-2014-02/0184.html
  • Loading branch information
ykimot authored and bagder committed Jul 15, 2014
1 parent f069b40 commit aa68848
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/url.c
Expand Up @@ -1169,18 +1169,20 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
if(argptr == NULL)
break;

Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);

if(Curl_raw_equal(argptr, "ALL")) {
/* clear all cookies */
Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
Curl_cookie_clearall(data->cookies);
Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
}
else if(Curl_raw_equal(argptr, "SESS")) {
/* clear session cookies */
Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
Curl_cookie_clearsess(data->cookies);
Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
}
else if(Curl_raw_equal(argptr, "FLUSH")) {
/* flush cookies to file */
/* flush cookies to file, takes care of the locking */
Curl_flush_cookies(data, 0);
}
else {
Expand All @@ -1193,6 +1195,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
result = CURLE_OUT_OF_MEMORY;
}
else {
Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);

if(checkprefix("Set-Cookie:", argptr))
/* HTTP Header format line */
Expand All @@ -1202,10 +1205,10 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
/* Netscape format line */
Curl_cookie_add(data, data->cookies, FALSE, argptr, NULL, NULL);

Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
free(argptr);
}
}
Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);

break;
#endif /* CURL_DISABLE_COOKIES */
Expand Down

0 comments on commit aa68848

Please sign in to comment.