Title: [153944] trunk/Source/WebCore
Revision
153944
Author
[email protected]
Date
2013-08-12 09:36:01 -0700 (Mon, 12 Aug 2013)

Log Message

[Curl] Crash when starting second download.
https://bugs.webkit.org/show_bug.cgi?id=119620

Patch by [email protected] <[email protected]> on 2013-08-12
Reviewed by Brent Fulgham.

When a second download is started, a crash sometimes occurs in Curl.
This happens because the Curl easy handle is deleted and removed from the Curl multi handle twice.
This is solved by adding an array to keep track of active downloads to avoid double deletion.

* platform/network/curl/CurlDownload.cpp:
(WebCore::CurlDownloadManager::CurlDownloadManager): Removed active download count member.
(WebCore::CurlDownloadManager::getActiveDownloadCount): Use active download array to return active download count.
(WebCore::CurlDownloadManager::updateHandleList): Remove Curl handles before adding, in case Curl reuses handles.
(WebCore::CurlDownloadManager::addToCurl): Add Curl handle to active download array.
(WebCore::CurlDownloadManager::removeFromCurl): Check if Curl handle is in active download array to avoid double deletion.
(WebCore::CurlDownloadManager::downloadThread): Removed active download count member.
* platform/network/curl/CurlDownload.h: Added array of active downloads member, and removed download count member.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (153943 => 153944)


--- trunk/Source/WebCore/ChangeLog	2013-08-12 16:32:57 UTC (rev 153943)
+++ trunk/Source/WebCore/ChangeLog	2013-08-12 16:36:01 UTC (rev 153944)
@@ -1,3 +1,23 @@
+2013-08-12  [email protected]  <[email protected]>
+
+        [Curl] Crash when starting second download.
+        https://bugs.webkit.org/show_bug.cgi?id=119620
+
+        Reviewed by Brent Fulgham.
+
+        When a second download is started, a crash sometimes occurs in Curl.
+        This happens because the Curl easy handle is deleted and removed from the Curl multi handle twice.
+        This is solved by adding an array to keep track of active downloads to avoid double deletion. 
+
+        * platform/network/curl/CurlDownload.cpp:
+        (WebCore::CurlDownloadManager::CurlDownloadManager): Removed active download count member.
+        (WebCore::CurlDownloadManager::getActiveDownloadCount): Use active download array to return active download count.
+        (WebCore::CurlDownloadManager::updateHandleList): Remove Curl handles before adding, in case Curl reuses handles.
+        (WebCore::CurlDownloadManager::addToCurl): Add Curl handle to active download array.
+        (WebCore::CurlDownloadManager::removeFromCurl): Check if Curl handle is in active download array to avoid double deletion.
+        (WebCore::CurlDownloadManager::downloadThread): Removed active download count member.
+        * platform/network/curl/CurlDownload.h: Added array of active downloads member, and removed download count member.
+
 2013-08-12  Antti Koivisto  <[email protected]>
 
         Add ElementTraversal::next/previousSibling

Modified: trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp (153943 => 153944)


--- trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp	2013-08-12 16:32:57 UTC (rev 153943)
+++ trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp	2013-08-12 16:36:01 UTC (rev 153944)
@@ -44,7 +44,6 @@
 CurlDownloadManager::CurlDownloadManager()
 : m_threadId(0)
 , m_curlMultiHandle(0)
-, m_activeDownloadCount(0)
 , m_runThread(false)
 {
     curl_global_init(CURL_GLOBAL_ALL);
@@ -79,7 +78,8 @@
 
 int CurlDownloadManager::getActiveDownloadCount() const
 {
-    return m_activeDownloadCount;
+    MutexLocker locker(m_mutex);
+    return m_activeHandleList.size();
 }
 
 int CurlDownloadManager::getPendingDownloadCount() const
@@ -120,31 +120,41 @@
 {
     MutexLocker locker(m_mutex);
 
+    // Remove curl easy handles from multi list 
+    int size = m_removedHandleList.size();
+    for (int i = 0; i < size; i++) {
+        if (removeFromCurl(m_removedHandleList[0]))
+            m_removedHandleList.remove(0);
+    }
+
     // Add pending curl easy handles to multi list 
-    int size = m_pendingHandleList.size();
+    size = m_pendingHandleList.size();
     for (int i = 0; i < size; i++) {
         if (addToCurl(m_pendingHandleList[0]))
             m_pendingHandleList.remove(0);
     }
-
-    // Remove curl easy handles from multi list 
-    size = m_removedHandleList.size();
-    for (int i = 0; i < size; i++) {
-        if (removeFromCurl(m_removedHandleList[0]))
-            m_removedHandleList.remove(0);
-    }
 }
 
 bool CurlDownloadManager::addToCurl(CURL* curlHandle)
 {
     CURLMcode retval = curl_multi_add_handle(m_curlMultiHandle, curlHandle);
-    return retval == CURLM_OK;
+    if (retval == CURLM_OK) {
+        m_activeHandleList.append(curlHandle);
+        return true;
+    }
+    return false;
 }
 
 bool CurlDownloadManager::removeFromCurl(CURL* curlHandle)
 {
+    int handlePos = m_activeHandleList.find(curlHandle);
+
+    if (handlePos < 0)
+        return true;
+    
     CURLMcode retval = curl_multi_remove_handle(m_curlMultiHandle, curlHandle);
     if (retval == CURLM_OK) {
+        m_activeHandleList.remove(handlePos);
         curl_easy_cleanup(curlHandle);
         return true;
     }
@@ -185,7 +195,8 @@
                 rc = ::select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
         } while (rc == -1 && errno == EINTR);
 
-        while (curl_multi_perform(downloadManager->getMultiHandle(), &downloadManager->m_activeDownloadCount) == CURLM_CALL_MULTI_PERFORM) { }
+        int activeDownloadCount = 0;
+        while (curl_multi_perform(downloadManager->getMultiHandle(), &activeDownloadCount) == CURLM_CALL_MULTI_PERFORM) { }
 
         int messagesInQueue = 0;
         CURLMsg* msg = curl_multi_info_read(downloadManager->getMultiHandle(), &messagesInQueue);

Modified: trunk/Source/WebCore/platform/network/curl/CurlDownload.h (153943 => 153944)


--- trunk/Source/WebCore/platform/network/curl/CurlDownload.h	2013-08-12 16:32:57 UTC (rev 153943)
+++ trunk/Source/WebCore/platform/network/curl/CurlDownload.h	2013-08-12 16:36:01 UTC (rev 153944)
@@ -69,8 +69,8 @@
 
     ThreadIdentifier m_threadId;
     CURLM* m_curlMultiHandle;
-    int m_activeDownloadCount;
     Vector<CURL*> m_pendingHandleList;
+    Vector<CURL*> m_activeHandleList;
     Vector<CURL*> m_removedHandleList;
     mutable Mutex m_mutex;
     bool m_runThread;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to