RESOLVED FIXED153932
ScrollbarPainters needs to be deallocated on the main thread
https://bugs.webkit.org/show_bug.cgi?id=153932
Summary ScrollbarPainters needs to be deallocated on the main thread
Beth Dakin
Reported 2016-02-05 17:01:22 PST
ScrollbarPainters needs to be deallocated on the main thread rdar://problem/24015483
Attachments
Patch (3.00 KB, patch)
2016-02-05 17:04 PST, Beth Dakin
thorton: review+
Patch, v3 (4.52 KB, patch)
2016-02-06 15:10 PST, Beth Dakin
mitz: review+
Beth Dakin
Comment 1 2016-02-05 17:04:03 PST
Tim Horton
Comment 2 2016-02-05 17:05:47 PST
Comment on attachment 270781 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=270781&action=review > Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:124 > + {}); Curly brace style.
WebKit Commit Bot
Comment 3 2016-02-05 17:05:59 PST
Attachment 270781 [details] did not pass style-queue: ERROR: Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:118: This { should be at the end of the previous line [whitespace/braces] [4] ERROR: Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:124: Missing space inside { }. [whitespace/braces] [5] Total errors found: 2 in 2 files If any of these errors are false positives, please file a bug against check-webkit-style.
Beth Dakin
Comment 4 2016-02-05 17:09:21 PST
Darin Adler
Comment 5 2016-02-06 08:40:51 PST
Comment on attachment 270781 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=270781&action=review > Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:75 > + RetainPtr<ScrollbarPainter> retainedVerticalScrollbarPainter = m_verticalScrollbarPainter; > + RetainPtr<ScrollbarPainter> retainedHorizontalScrollbarPainter = m_horizontalScrollbarPainter; > + WTF::callOnMainThread([retainedVerticalScrollbarPainter, retainedHorizontalScrollbarPainter] { }); I don’t think this is guaranteed to work. There will be six RetainPtr objects, two in the data members, two local variables, and two captured by the lambda. That seems to set up a race condition. If the call on the main thread completes before the ScrollingTreeFrameScrollingNodeMac is finished being destroyed, then the NSScrollerImp objects will still be deallocated on this thread. Actually I see in the code that was actually landed we use WTFMove. This gets rid of two of the six RetainPtr objects, but there is still a race condition between the destruction of the two local variables and the destruction of the lambda on the main thread. I’m not sure there is a way to do this with RetainPtr without more advanced C++ lambda support than we currently have. But we can do it safely if we don’t use RetainPtr. Here’s one way of writing it without the race condition: auto* retainedVerticalScrollbarPainter = m_verticalScrollbarPainter.leakRef(); auto* retainedHorizontalScrollbarPainter = m_horizontalScrollbarPainter.leakRef(); WTF::callOnMainThread([retainedVerticalScrollbarPainter, retainedHorizontalScrollbarPainter] { [retainedVerticalScrollbarPainter release]; [retainedHorizontalScrollbarPainter release]; }); > Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:123 > + RetainPtr<ScrollbarPainter> retainedVerticalScrollbarPainter = m_verticalScrollbarPainter; > + RetainPtr<ScrollbarPainter> retainedHorizontalScrollbarPainter = m_horizontalScrollbarPainter; > + WTF::callOnMainThread([retainedVerticalScrollbarPainter, retainedHorizontalScrollbarPainter] Same issue here, which can be fixed the same way. Also unclear on why we are not doing the null check here that we are doing in the destructor. Maybe share a helper function?
Beth Dakin
Comment 6 2016-02-06 15:00:50 PST
Yup, you are totally right. Okay, I will post a new patch. (In reply to comment #5) > Comment on attachment 270781 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=270781&action=review > > > Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:75 > > + RetainPtr<ScrollbarPainter> retainedVerticalScrollbarPainter = m_verticalScrollbarPainter; > > + RetainPtr<ScrollbarPainter> retainedHorizontalScrollbarPainter = m_horizontalScrollbarPainter; > > + WTF::callOnMainThread([retainedVerticalScrollbarPainter, retainedHorizontalScrollbarPainter] { }); > > I don’t think this is guaranteed to work. There will be six RetainPtr > objects, two in the data members, two local variables, and two captured by > the lambda. That seems to set up a race condition. If the call on the main > thread completes before the ScrollingTreeFrameScrollingNodeMac is finished > being destroyed, then the NSScrollerImp objects will still be deallocated on > this thread. > > Actually I see in the code that was actually landed we use WTFMove. This > gets rid of two of the six RetainPtr objects, but there is still a race > condition between the destruction of the two local variables and the > destruction of the lambda on the main thread. > > I’m not sure there is a way to do this with RetainPtr without more advanced > C++ lambda support than we currently have. But we can do it safely if we > don’t use RetainPtr. Here’s one way of writing it without the race condition: > > auto* retainedVerticalScrollbarPainter = > m_verticalScrollbarPainter.leakRef(); > auto* retainedHorizontalScrollbarPainter = > m_horizontalScrollbarPainter.leakRef(); > WTF::callOnMainThread([retainedVerticalScrollbarPainter, > retainedHorizontalScrollbarPainter] { > [retainedVerticalScrollbarPainter release]; > [retainedHorizontalScrollbarPainter release]; > }); > > > Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:123 > > + RetainPtr<ScrollbarPainter> retainedVerticalScrollbarPainter = m_verticalScrollbarPainter; > > + RetainPtr<ScrollbarPainter> retainedHorizontalScrollbarPainter = m_horizontalScrollbarPainter; > > + WTF::callOnMainThread([retainedVerticalScrollbarPainter, retainedHorizontalScrollbarPainter] > > Same issue here, which can be fixed the same way. Also unclear on why we are > not doing the null check here that we are doing in the destructor. Maybe > share a helper function?
Beth Dakin
Comment 7 2016-02-06 15:10:45 PST
Created attachment 270806 [details] Patch, v3
mitz
Comment 8 2016-02-06 15:37:01 PST
Comment on attachment 270806 [details] Patch, v3 View in context: https://bugs.webkit.org/attachment.cgi?id=270806&action=review > Source/WebCore/ChangeLog:11 > + condition between the destruction of the two local variables and the d “the d”
Beth Dakin
Comment 9 2016-02-06 15:42:52 PST
Note You need to log in before you can comment on or make changes to this bug.