Changeset 102863 in webkit


Ignore:
Timestamp:
Dec 14, 2011 6:02:59 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[chromium] Fix CCLayerTreeHostTest shutdown race
https://bugs.webkit.org/show_bug.cgi?id=73926

This patch fixes a shutdown race condition in CCLayerTreeHostTest which
may happen if endTest() is called from within the drawLayersOnCCThread()
test hook. The sequence of events leading to the problem is:

  1. CCThreadProxy::scheduledActionDrawAndSwap() is called when a frame begins.
  2. CCThreadProxy calls drawLayersOnCCThread(), which in turn calls endTest().
  3. Seeing it's not running in the main thread, endTest() posts a task calling itself in the main thread.
  4. CCThreadProxy posts a task for calling didCommitAndDrawFrame() in the main thread.

The race is between the task posted in step #3 and the CC thread running
in scheduledActionDrawAndSwap(). If the endTask() task is scheduled
before the CC thread reaches step #4, it drains the pending message
queue (CCLayerTreeHostTest.cpp:369) before the task in step #4 is
posted.

The result is that the didCommitAndDrawFrame() task is executed after
the test fixture has been torn down, causing a read of unallocated
memory in CCScopedThreadProxy::runTaskIfNotShutdown (as m_targetThread
is no longer valid).

The fix is check m_shutdown before touching m_targetThread in
CCScopedThreadProxy. That is, events will still be queued after shutdown
but they will not be processed.

Patch by Sami Kyostila <skyostil@chromium.org> on 2011-12-14
Reviewed by James Robinson.

Location:
trunk/Source
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCScopedThreadProxy.h

    r100370 r102863  
    7272    void runTaskIfNotShutdown(PassOwnPtr<CCThread::Task> popTask)
    7373    {
     74        OwnPtr<CCThread::Task> task = popTask;
     75        // If our shutdown flag is set, it's possible that m_targetThread has already been destroyed so don't
     76        // touch it.
     77        if (m_shutdown) {
     78            deref();
     79            return;
     80        }
    7481        ASSERT(currentThread() == m_targetThread->threadID());
    75         OwnPtr<CCThread::Task> task = popTask;
    76         if (!m_shutdown)
    77             task->performTask();
     82        task->performTask();
    7883        deref();
    7984    }
  • trunk/Source/WebKit/chromium/ChangeLog

    r102817 r102863  
     12011-12-14  Sami Kyostila  <skyostil@chromium.org>
     2
     3        [chromium] Fix CCLayerTreeHostTest shutdown race
     4        https://bugs.webkit.org/show_bug.cgi?id=73926
     5
     6        This patch fixes a shutdown race condition in CCLayerTreeHostTest which
     7        may happen if endTest() is called from within the drawLayersOnCCThread()
     8        test hook. The sequence of events leading to the problem is:
     9
     10          1. CCThreadProxy::scheduledActionDrawAndSwap() is called when a frame
     11             begins.
     12          2. CCThreadProxy calls drawLayersOnCCThread(), which in turn calls
     13             endTest().
     14          3. Seeing it's not running in the main thread, endTest() posts a task
     15             calling itself in the main thread.
     16          4. CCThreadProxy posts a task for calling didCommitAndDrawFrame() in
     17             the main thread.
     18
     19        The race is between the task posted in step #3 and the CC thread running
     20        in scheduledActionDrawAndSwap(). If the endTask() task is scheduled
     21        before the CC thread reaches step #4, it drains the pending message
     22        queue (CCLayerTreeHostTest.cpp:369) before the task in step #4 is
     23        posted.
     24
     25        The result is that the didCommitAndDrawFrame() task is executed after
     26        the test fixture has been torn down, causing a read of unallocated
     27        memory in CCScopedThreadProxy::runTaskIfNotShutdown (as m_targetThread
     28        is no longer valid).
     29
     30        The fix is check m_shutdown before touching m_targetThread in
     31        CCScopedThreadProxy. That is, events will still be queued after shutdown
     32        but they will not be processed.
     33
     34        Reviewed by James Robinson.
     35
    1362011-12-14  Jonathan Backer  <backer@chromium.org>
    237
Note: See TracChangeset for help on using the changeset viewer.