Bug 211844 - JSDOMWindowBase m_windowCloseWatchpoints must be Ref<>
Summary: JSDOMWindowBase m_windowCloseWatchpoints must be Ref<>
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Bindings (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-05-13 08:58 PDT by xc.o.c.1180@gmail.com
Modified: 2020-05-13 19:16 PDT (History)
9 users (show)

See Also:


Attachments
patch (2.03 KB, text/plain)
2020-05-13 08:58 PDT, xc.o.c.1180@gmail.com
no flags Details
Patch (10.67 KB, patch)
2020-05-13 17:30 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description xc.o.c.1180@gmail.com 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.
Comment 1 Chris Dumez 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.
Comment 2 xc.o.c.1180@gmail.com 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.
Comment 3 Yusuke Suzuki 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.
Comment 4 Yusuke Suzuki 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.
Comment 5 Yusuke Suzuki 2020-05-13 17:30:49 PDT
Created attachment 399319 [details]
Patch
Comment 6 Mark Lam 2020-05-13 17:39:06 PDT
Comment on attachment 399319 [details]
Patch

r=me
Comment 7 EWS 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].
Comment 8 Radar WebKit Bug Importer 2020-05-13 19:16:17 PDT
<rdar://problem/63210610>