[Webkit-unassigned] [Bug 121284] New: TimerWindowWndProc and dangling page instances

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Sep 13 02:52:47 PDT 2013


https://bugs.webkit.org/show_bug.cgi?id=121284

           Summary: TimerWindowWndProc and dangling page instances
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: All
        OS/Version: All
            Status: UNCONFIRMED
          Severity: Normal
          Priority: P2
         Component: New Bugs
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: Vincent.VanDenBerghe at bvdinfo.com
                CC: darin at apple.com


Created an attachment (id=211525)
 --> (https://bugs.webkit.org/attachment.cgi?id=211525&action=review)
Minimal patch to correct dangling pages bug

Background
----------
I’m currently embedding WebKit in a .NET application, which required me to solve a whole set of issues that are not relevant here. However, I’ve stumbled upon a scenario which I suspect is *really* problematic (but I can be wrong). Before patching anything, I’d like to submit this to greater minds for validation. The version of WebKit to which this applies is irrelevant: any recent version will do. Note: preliminary feedback from Darin Adler seems to indicate this is a platform-wide problem.

Problem
-------
When I’m finish with a WebView instance and before I’m releasing the COM object, I close it by doing a 

DestroyWindow(m_viewWindow) 

…where m_viewWindow is WebView’s view window. Note that calling WebView::close() would work just as well.
This triggers a sequence of events that ultimately causes the destructor of the page to be called:

Page::~Page()

This works well, but when stress testing this will crash the WebKit.DLL with the following stack trace:

                WebKit.dll!WebCore::setImageLoadingSettings(WebCore::Page * page)  Line 57 + 0x3 bytes      C++
               WebKit.dll!WebCore::Settings::imageLoadingSettingsTimerFired(WebCore::Timer<WebCore::Settings> * __formal)  Line 363 + 0x8 bytes C++
               WebKit.dll!WebCore::Timer<WebCore::XMLHttpRequestProgressEventThrottle>::fired()  Line 114 + 0xb bytes C++
               WebKit.dll!WebCore::ThreadTimers::sharedTimerFiredInternal()  Line 132           C++
               WebKit.dll!WebCore::TimerWindowWndProc(HWND__ * hWnd, unsigned int message, unsigned int wParam, long lParam)  Line 111              C++

Depending on the managed environment (details are irrelevant for this discussion), the crash happens either immediately or after a while. Because of the way I embed WebKit, this usually happens when the second (or third, forth…) instance is being created.
The visible cause of the crash is the call to 

WebKit.dll!WebCore::setImageLoadingSettings(WebCore::Page * page)

... with a page instance for which its destructor has already been executed.

Primary Cause
-------------
I suspect the primary cause of a crash is the pending timer whose message is still in the message queue, that is executed just after the destruction of the page, but before any pending timers are killed. This causes a delayed execution of a function on a dangling page instance.
The problem doesn’t occur when I don’t call DestroyWindow or WebView::Close(), but this leads to unacceptable memory leaks.

Workaround
----------
The minimal workaround is to add a method to WebCore::Settings:

void Settings::detachFromPage()
{
    m_page = 0;
    m_setImageLoadingSettingsTimer.stop();
}


And call this method as the first line of Page’s destructor:

Page::~Page()
{
    m_settings->detachFromPage();
    m_mainFrame->setView(0);
…


…and finally add if(page) guard in various places in WebCore::Settings (see attachment).
This doesn’t remedy the delayed execution of the timer, but solves the problem by setting the deleted instance to NULL and making sure it’s not used in the delayed call.

I have little time to follow all the rules and submit a patch and don't have the absolute latest tree anyway, but I have included a patch attachment so that anyone who is inclined to do so can take it as a starting point.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the webkit-unassigned mailing list