Bug 84307

Summary: [WK2] AlternativeTextClient leaks when the page is destroyed
Product: WebKit Reporter: Andreas Kling <kling>
Component: HTML EditingAssignee: Jon Lee <jonlee>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, ap, darin, enrica, eric, jiapu.mail, jonlee, morrita, rniwa, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Fix memory leak.
none
Use OwnPtr.
none
Patch enrica: review+

Description Andreas Kling 2012-04-18 17:55:03 PDT
There is nobody deleting the WebKit::WebAlternativeTextClient AFAICT. Opening and closing a couple of pages, and then running "leaks" will show you that a bunch of WebAlternativeTextClient objects have leaked.
Comment 1 Jia Pu 2012-04-18 18:19:09 PDT
Will take a look.
Comment 2 Jia Pu 2012-04-19 12:02:21 PDT
Created attachment 137942 [details]
Fix memory leak.
Comment 3 Eric Seidel (no email) 2012-04-19 14:31:54 PDT
I thought we had a PageObserver pattern these days?
Comment 4 Eric Seidel (no email) 2012-04-19 14:32:14 PDT
I guess only FrameDestructionObserver.
Comment 5 Ryosuke Niwa 2012-04-21 18:46:35 PDT
Comment on attachment 137942 [details]
Fix memory leak.

View in context: https://bugs.webkit.org/attachment.cgi?id=137942&action=review

> Source/WebKit/mac/WebCoreSupport/WebAlternativeTextClient.mm:45
> +void WebAlternativeTextClient::pageDestroyed()
> +{
> +    delete this;
> +}

Really? We need to manually call delete on this? Can't we use OwnPtr instead?
Comment 6 Jia Pu 2012-04-21 19:05:16 PDT
(In reply to comment #5)
> (From update of attachment 137942 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=137942&action=review
> 
> > Source/WebKit/mac/WebCoreSupport/WebAlternativeTextClient.mm:45
> > +void WebAlternativeTextClient::pageDestroyed()
> > +{
> > +    delete this;
> > +}
> 
> Really? We need to manually call delete on this? Can't we use OwnPtr instead?

I am just following this pattern in various other clients. I can certainly just release it on WebCore side.
Comment 7 Tim Horton 2012-04-22 19:36:49 PDT
Comment on attachment 137942 [details]
Fix memory leak.

View in context: https://bugs.webkit.org/attachment.cgi?id=137942&action=review

> Source/WebKit2/ChangeLog:8
> +        Fixing memory leak.

The changelog entry could definitely be slightly more informative re: what situation we were leaking in and how it's fixed; as it stands, it's impossible to know much about what's going on without looking at the change itself.
Comment 8 Jia Pu 2012-04-23 14:02:03 PDT
Created attachment 138421 [details]
Use OwnPtr.
Comment 9 Darin Adler 2012-04-23 15:19:06 PDT
The other clients aren’t owned like this. Why is the pattern different for this one?
Comment 10 Darin Adler 2012-04-23 15:20:15 PDT
(In reply to comment #5)
> We need to manually call delete on this? Can't we use OwnPtr instead?

We shouldn’t because the ownership is not something Page enforces. It’s something that can vary per-port. If we were going to use OwnPtr we’d want to use it in the clients structure itself and remove the flexibility of having the clients not all be separate objects, flexibility we have today.
Comment 11 Darin Adler 2012-04-23 15:21:01 PDT
Another way to put it is that if we are going to use OwnPtr, then the adoptPtr needs to be right next to the new, not inside the Page constructor’s implementation.
Comment 12 Jia Pu 2012-04-23 15:24:03 PDT
Would the first patch look OK then?
Comment 13 Jon Lee 2012-04-26 12:57:22 PDT
*** Bug 84984 has been marked as a duplicate of this bug. ***
Comment 14 Jon Lee 2012-04-26 12:59:06 PDT
<rdar://problem/11328431>
Comment 15 Jon Lee 2012-04-26 13:01:43 PDT
I had filed a similar bug and posted a patch exactly like the _first_ one that Jia had posted. The pattern, while not ideal, is established in other clients. So given that my patch is exactly what Jia did, I would unofficially r+ the first patch.
Comment 16 Jon Lee 2012-04-26 14:28:28 PDT
Talked to Jia offline, reassigning to me.
Comment 17 Jon Lee 2012-04-26 14:29:09 PDT
Created attachment 139071 [details]
Patch
Comment 18 Enrica Casucci 2012-04-26 14:31:49 PDT
Comment on attachment 139071 [details]
Patch

Looks good.
Comment 19 Jon Lee 2012-04-26 14:34:44 PDT
Committed r115369: <http://trac.webkit.org/changeset/115369>