RESOLVED FIXED 211844
JSDOMWindowBase m_windowCloseWatchpoints must be Ref<>
https://bugs.webkit.org/show_bug.cgi?id=211844
Summary JSDOMWindowBase m_windowCloseWatchpoints must be Ref<>
xc.o.c.1180@gmail.com
Reported 2020-05-13 08:58:56 PDT
Created attachment 399266 [details] patch JSC WatchpointSet is reference counted, however m_windowCloseWatchpoints is just a member variable. ProxyableAccessCase holds on it, when JSDOMWindowBase is destroyed, m_additionalSet holds a dangling pointer. By the way, WatchpointSet constructor should be private. I can not build latest WebKit, please clean up the patch, add other stuffs, then commit it. Thanks.
Attachments
patch (2.03 KB, text/plain)
2020-05-13 08:58 PDT, xc.o.c.1180@gmail.com
no flags
Patch (10.67 KB, patch)
2020-05-13 17:30 PDT, Yusuke Suzuki
no flags
Chris Dumez
Comment 1 2020-05-13 12:40:24 PDT
(In reply to xc.o.c.1180@gmail.com from comment #0) > Created attachment 399266 [details] > patch > > JSC WatchpointSet is reference counted, however m_windowCloseWatchpoints is > just a member variable. > > ProxyableAccessCase holds on it, when JSDOMWindowBase is destroyed, > m_additionalSet holds a dangling pointer. > > By the way, WatchpointSet constructor should be private. > > I can not build latest WebKit, please clean up the patch, add other stuffs, > then commit it. > > > Thanks. We are unable to approve / commit patches without test cases.
xc.o.c.1180@gmail.com
Comment 2 2020-05-13 13:26:28 PDT
Test case is not practical, it depends on memory access. First, JSDOMWindowBase must be destroyed before ProxyableAccessCase which holds its m_windowCloseWatchpoints, this step is possible. Second, since WatchpointSet is reference counted, the memory which has m_windowCloseWatchpoints's reference counter must be 1, otherwise, ProxyableAccessCase does not destroy its m_additionalSet (JSDOMWindowBase's m_windowCloseWatchpoints) when itself is deleted. This step is not practical in test case.
Yusuke Suzuki
Comment 3 2020-05-13 14:00:23 PDT
(In reply to xc.o.c.1180@gmail.com from comment #2) > Test case is not practical, it depends on memory access. > > First, JSDOMWindowBase must be destroyed before ProxyableAccessCase which > holds its m_windowCloseWatchpoints, this step is possible. I think this is possible while I don't come up with the test case. > > Second, since WatchpointSet is reference counted, the memory which has > m_windowCloseWatchpoints's reference counter must be 1, otherwise, > ProxyableAccessCase does not destroy its m_additionalSet (JSDOMWindowBase's > m_windowCloseWatchpoints) when itself is deleted. This step is not practical > in test case. The initial m_refCount of RefCounted object is 1. And when wrapping this with Ref<> initially at construction, we do not increment it because of this (this is called "adopt". See adoptRef). So this does not matter.
Yusuke Suzuki
Comment 4 2020-05-13 17:29:56 PDT
(In reply to Yusuke Suzuki from comment #3) > (In reply to xc.o.c.1180@gmail.com from comment #2) > > Test case is not practical, it depends on memory access. > > > > First, JSDOMWindowBase must be destroyed before ProxyableAccessCase which > > holds its m_windowCloseWatchpoints, this step is possible. > > I think this is possible while I don't come up with the test case. After looking into this deeply, I think this does not matter. ProxyableAccessCase has Structure, and this Structure will point to JSDOMWindow. So, as long as ProxyableAccessCase is alive, JSDOMWindow is also alive. But anyway, using RefCounted object without RefCount-creation is not good. I'll fix it.
Yusuke Suzuki
Comment 5 2020-05-13 17:30:49 PDT
Mark Lam
Comment 6 2020-05-13 17:39:06 PDT
Comment on attachment 399319 [details] Patch r=me
EWS
Comment 7 2020-05-13 19:15:37 PDT
Committed r261668: <https://trac.webkit.org/changeset/261668> All reviewed patches have been landed. Closing bug and clearing flags on attachment 399319 [details].
Radar WebKit Bug Importer
Comment 8 2020-05-13 19:16:17 PDT
Note You need to log in before you can comment on or make changes to this bug.