Changeset 207454 in webkit


Ignore:
Timestamp:
Oct 17, 2016 11:03:55 PM (7 years ago)
Author:
Carlos Garcia Campos
Message:

NetworkSession: PendingDownload is leaked if canceled before willDecidePendingDownloadDestination
https://bugs.webkit.org/show_bug.cgi?id=163545

Reviewed by Alex Christensen.

If a download started by DownloadManager::startDownload() is cancelled before
DownloadManager::willDecidePendingDownloadDestination() is called, DownloadManager::cancelDownload() does
nothing, because the Download hasn't been created yet and m_downloadsWaitingForDestination map doesn't contain
the download ID, and the PendingDownload is never removed from the m_pendingDownloads map.

  • NetworkProcess/Downloads/DownloadManager.cpp:

(WebKit::DownloadManager::cancelDownload): Always take the PendingDownload from m_pendingDownloads map. Then, if
the download was already in m_downloadsWaitingForDestination map, get the network data task to properly cancel
it and then call the completion handler to ignore the request. Otherwise cancel the pending download if exists.

  • NetworkProcess/Downloads/PendingDownload.cpp:

(WebKit::PendingDownload::cancel): Cancel the network load and notify the UI process that the download was canceled.

  • NetworkProcess/Downloads/PendingDownload.h:
Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r207447 r207454  
     12016-10-17  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        NetworkSession: PendingDownload is leaked if canceled before willDecidePendingDownloadDestination
     4        https://bugs.webkit.org/show_bug.cgi?id=163545
     5
     6        Reviewed by Alex Christensen.
     7
     8        If a download started by DownloadManager::startDownload() is cancelled before
     9        DownloadManager::willDecidePendingDownloadDestination() is called, DownloadManager::cancelDownload() does
     10        nothing, because the Download hasn't been created yet and m_downloadsWaitingForDestination map doesn't contain
     11        the download ID, and the PendingDownload is never removed from the m_pendingDownloads map.
     12
     13        * NetworkProcess/Downloads/DownloadManager.cpp:
     14        (WebKit::DownloadManager::cancelDownload): Always take the PendingDownload from m_pendingDownloads map. Then, if
     15        the download was already in m_downloadsWaitingForDestination map, get the network data task to properly cancel
     16        it and then call the completion handler to ignore the request. Otherwise cancel the pending download if exists.
     17        * NetworkProcess/Downloads/PendingDownload.cpp:
     18        (WebKit::PendingDownload::cancel): Cancel the network load and notify the UI process that the download was canceled.
     19        * NetworkProcess/Downloads/PendingDownload.h:
     20
    1212016-10-17  Megan Gardner  <megan_gardner@apple.com>
    222
  • trunk/Source/WebKit2/NetworkProcess/Downloads/DownloadManager.cpp

    r207042 r207454  
    159159{
    160160    if (Download* download = m_downloads.get(downloadID)) {
     161#if USE(NETWORK_SESSION)
     162        ASSERT(!m_downloadsWaitingForDestination.contains(downloadID));
     163        ASSERT(!m_pendingDownloads.contains(downloadID));
     164#endif
    161165        download->cancel();
    162166        return;
    163167    }
    164168#if USE(NETWORK_SESSION)
    165     if (auto completionHandler = m_downloadsWaitingForDestination.take(downloadID).second) {
     169    auto pendingDownload = m_pendingDownloads.take(downloadID);
     170    if (m_downloadsWaitingForDestination.contains(downloadID)) {
     171        auto pair = m_downloadsWaitingForDestination.take(downloadID);
     172        auto networkDataTask = WTFMove(pair.first);
     173        auto completionHandler = WTFMove(pair.second);
     174        ASSERT(networkDataTask);
     175        ASSERT(completionHandler);
     176
     177        networkDataTask->cancel();
     178        completionHandler(PolicyIgnore);
    166179        m_client.pendingDownloadCanceled(downloadID);
    167         completionHandler(PolicyIgnore);
    168         return;
    169     }
     180        return;
     181    }
     182
     183    if (pendingDownload)
     184        pendingDownload->cancel();
    170185#endif
    171186}
  • trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.cpp

    r206988 r207454  
    5959}
    6060
     61void PendingDownload::cancel()
     62{
     63    ASSERT(m_networkLoad);
     64    m_networkLoad->cancel();
     65    send(Messages::DownloadProxy::DidCancel({ }));
     66}
     67
    6168#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
    6269void PendingDownload::canAuthenticateAgainstProtectionSpaceAsync(const WebCore::ProtectionSpace& protectionSpace)
  • trunk/Source/WebKit2/NetworkProcess/Downloads/PendingDownload.h

    r206583 r207454  
    5252    void continueCanAuthenticateAgainstProtectionSpace(bool canAuthenticate);
    5353#endif
     54    void cancel();
    5455
    5556private:   
Note: See TracChangeset for help on using the changeset viewer.