Changeset 32871 in webkit


Ignore:
Timestamp:
May 5, 2008 9:09:00 AM (16 years ago)
Author:
Antti Koivisto
Message:

2008-05-05 Antti Koivisto <Antti Koivisto>

Reviewed by Darin.

Speculative fix for <rdar://problem/5906790>
Crash in Loader::servePendingRequests() due to hash table being modified during iteration


I don't know how to reproduce this. It would require the load to fail (or succeed)
synchronously, something that should not usually happen.

  • loader/loader.cpp: (WebCore::Loader::Loader): (WebCore::Loader::load): (WebCore::Loader::servePendingRequests): (WebCore::Loader::cancelRequests): (WebCore::Loader::Host::Host):
  • loader/loader.h: (WebCore::Loader::Host::name):
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r32868 r32871  
     12008-05-05  Antti Koivisto  <antti@apple.com>
     2
     3        Reviewed by Darin.
     4
     5        Speculative fix for <rdar://problem/5906790>
     6        Crash in Loader::servePendingRequests() due to hash table being modified during iteration
     7       
     8        I don't know how to reproduce this. It would require the load to fail (or succeed)
     9        synchronously, something that should not usually happen.
     10
     11        * loader/loader.cpp:
     12        (WebCore::Loader::Loader):
     13        (WebCore::Loader::load):
     14        (WebCore::Loader::servePendingRequests):
     15        (WebCore::Loader::cancelRequests):
     16        (WebCore::Loader::Host::Host):
     17        * loader/loader.h:
     18        (WebCore::Loader::Host::name):
     19
    1202008-05-05  Ariya Hidayat  <ariya.hidayat@trolltech.com>
    221
  • trunk/WebCore/loader/loader.cpp

    r31926 r32871  
    5959   
    6060Loader::Loader()
    61     : m_nonHTTPProtocolHost(maxRequestsInFlightForNonHTTPProtocols)
     61    : m_nonHTTPProtocolHost("non-http-protocol-host", maxRequestsInFlightForNonHTTPProtocols)
    6262    , m_requestTimer(this, &Loader::requestTimerFired)
    6363{
     
    103103    bool isHTTP = url.protocolIs("http") || url.protocolIs("https");
    104104    if (isHTTP) {
    105         String hostName = url.host();
    106         host = m_hosts.get(hostName);
     105        AtomicString hostName = url.host();
     106        host = m_hosts.get(hostName.impl());
    107107        if (!host) {
    108             host = new Host(maxRequestsInFlightPerHost);
    109             m_hosts.add(hostName, host);
     108            host = new Host(hostName, maxRequestsInFlightPerHost);
     109            m_hosts.add(hostName.impl(), host);
    110110        }
    111111    } else
     
    142142    m_nonHTTPProtocolHost.servePendingRequests(minimumPriority);
    143143
    144     HostMap::iterator end = m_hosts.end();
    145     Vector<String> toRemove;
    146     for (HostMap::iterator it = m_hosts.begin(); it != end; ++it) {
    147         Host* host = it->second;
     144    Vector<Host*> hostsToServe;
     145    copyValuesToVector(m_hosts, hostsToServe);
     146    for (unsigned n = 0; n < hostsToServe.size(); ++n) {
     147        Host* host = hostsToServe[n];
    148148        if (host->hasRequests())
    149149            host->servePendingRequests(minimumPriority);
    150         else
    151             toRemove.append(it->first);
    152     }
    153     for (unsigned n = 0; n < toRemove.size(); ++n) {
    154         HostMap::iterator it = m_hosts.find(toRemove[n]);
    155         delete it->second;
    156         m_hosts.remove(it);
     150        else {
     151            AtomicString name = host->name();
     152            delete host;
     153            m_hosts.remove(name.impl());
     154        }
    157155    }
    158156}
     
    163161        m_nonHTTPProtocolHost.cancelRequests(docLoader);
    164162   
    165     HostMap::iterator end = m_hosts.end();
    166     for (HostMap::iterator it = m_hosts.begin(); it != end; ++it) {
    167         Host* host = it->second;
     163    Vector<Host*> hostsToCancel;
     164    copyValuesToVector(m_hosts, hostsToCancel);
     165    for (unsigned n = 0; n < hostsToCancel.size(); ++n) {
     166        Host* host = hostsToCancel[n];
    168167        if (host->hasRequests())
    169168            host->cancelRequests(docLoader);
     
    178177}
    179178   
    180 Loader::Host::Host(unsigned maxRequestsInFlight)
    181     : m_maxRequestsInFlight(maxRequestsInFlight)
     179Loader::Host::Host(const AtomicString& name, unsigned maxRequestsInFlight)
     180    : m_name(name)
     181    , m_maxRequestsInFlight(maxRequestsInFlight)
    182182{
    183183}
  • trunk/WebCore/loader/loader.h

    r31038 r32871  
    2323#define loader_h
    2424
     25#include "AtomicString.h"
     26#include "AtomicStringImpl.h"
    2527#include "PlatformString.h"
    26 #include "StringHash.h"
    2728#include "SubresourceLoaderClient.h"
    2829#include "Timer.h"
     
    5758        class Host : private SubresourceLoaderClient {
    5859        public:
    59             Host(unsigned maxRequestsInFlight);
     60            Host(const AtomicString& name, unsigned maxRequestsInFlight);
    6061            ~Host();
    6162           
     63            const AtomicString& name() const { return m_name; }
    6264            void addRequest(Request*, Priority);
    6365            void servePendingRequests(Priority minimumPriority = Low);
     
    7981            typedef HashMap<RefPtr<SubresourceLoader>, Request*> RequestMap;
    8082            RequestMap m_requestsLoading;
     83            const AtomicString m_name;
    8184            const int m_maxRequestsInFlight;
    8285        };
    83         typedef HashMap<String, Host*> HostMap;
     86        typedef HashMap<AtomicStringImpl*, Host*> HostMap;
    8487        HostMap m_hosts;
    8588        Host m_nonHTTPProtocolHost;
Note: See TracChangeset for help on using the changeset viewer.