Bug 100237 - IconDatabase: Properly clean up on destruction
Summary: IconDatabase: Properly clean up on destruction
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jocelyn Turcotte
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-24 05:20 PDT by Jocelyn Turcotte
Modified: 2012-11-01 08:18 PDT (History)
4 users (show)

See Also:


Attachments
Patch (2.74 KB, patch)
2012-10-24 05:27 PDT, Jocelyn Turcotte
no flags Details | Formatted Diff | Diff
Patch (2.61 KB, patch)
2012-10-24 10:42 PDT, Jocelyn Turcotte
no flags Details | Formatted Diff | Diff
Patch (2.75 KB, patch)
2012-10-25 09:47 PDT, Jocelyn Turcotte
beidson: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jocelyn Turcotte 2012-10-24 05:20:21 PDT
IconDatabase: Properly cleanup on destruction
Comment 1 Jocelyn Turcotte 2012-10-24 05:27:39 PDT
Created attachment 170373 [details]
Patch
Comment 2 Brady Eidson 2012-10-24 08:50:27 PDT
Comment on attachment 170373 [details]
Patch

We don't clean up C++ objects on termination in WebCore/WebKit.

The IconDatabase should be explicitly closed by each port in a way that makes sense for them.
Comment 3 Brady Eidson 2012-10-24 08:52:52 PDT
(In reply to comment #2)
> (From update of attachment 170373 [details])
> We don't clean up C++ objects on termination in WebCore/WebKit.
> 
> The IconDatabase should be explicitly closed by each port in a way that makes sense for them.

To further elaborate, the WKIconDatabaseClose() API exists to explicitly do this from the embedding application.  On Mac, we want this to be explicit and not automatic.

If you want it to be automatic in your port then you should put an explicit ::close() call in your port's shutdown code (assuming there is any, which there probably is...!)
Comment 4 Jocelyn Turcotte 2012-10-24 10:42:51 PDT
Created attachment 170427 [details]
Patch

Ok, good to know.
Tell me how this looks now, I'll do the close() in WebContext::platformInvalidateContext in another patch.
Comment 5 Brady Eidson 2012-10-24 10:56:41 PDT
Comment on attachment 170427 [details]
Patch

You should only explicitly call ::close() on the WebCore::IconDatabase.  You should not actually cause it to be destroyed.

We don't run destructors at exit time.
Comment 6 Brady Eidson 2012-10-24 10:57:31 PDT
I would suggest that in your platform specific code that is run at shut down, you simply call WebIconDatabase::close()
Comment 7 Jocelyn Turcotte 2012-10-25 03:26:02 PDT
(In reply to comment #5)
> We don't run destructors at exit time.

The thing is that I want to allow the WebContext to be destroyed after the application destroys the last page and continues running. It's most likely not a full web browser in that case, but we still allow using the icon database.

Since WebIconDatabase is refcounted and keeps the WebCore::IconDatabase in an OwnPtr, it will be destroyed with the WebContext which usually owns the last reference to the WebIconDatabase.
I might be wrong somewhere so please correct me, but the only way I can see the IconDatabase not being destroyed is if the client code is expected to keep a reference outside WebKit to the WebIconDatabase or the WebContext until shutdown, and I can't enforce this.

Another example is in WebIconDatabase::setDatabasePath where m_iconDatabaseImpl.clear() is called. This will also destroy the WebCore::IconDatabase and the assert will be hit.
Comment 8 Brady Eidson 2012-10-25 08:58:41 PDT
(In reply to comment #7)
> (In reply to comment #5)
> > We don't run destructors at exit time.
> 
> The thing is that I want to allow the WebContext to be destroyed after the application destroys the last page and continues running. It's most likely not a full web browser in that case, but we still allow using the icon database.
> 
> Since WebIconDatabase is refcounted and keeps the WebCore::IconDatabase in an OwnPtr, it will be destroyed with the WebContext which usually owns the last reference to the WebIconDatabase.
> I might be wrong somewhere so please correct me, but the only way I can see the IconDatabase not being destroyed is if the client code is expected to keep a reference outside WebKit to the WebIconDatabase or the WebContext until shutdown, and I can't enforce this.
> 
> Another example is in WebIconDatabase::setDatabasePath where m_iconDatabaseImpl.clear() is called. This will also destroy the WebCore::IconDatabase and the assert will be hit.

I see...  interesting.

In that case, the existing ASSERT is definitely invalid.  But then we want to more explicitly enforce the "destruction shouldn't do meaningful cleanup" rule.

Could you change the ASSERT in the IconDatabase destructor to be:
ASSERT(!isOpen())
Comment 9 Jocelyn Turcotte 2012-10-25 09:47:24 PDT
Created attachment 170676 [details]
Patch

Sounds good.
Comment 10 Jocelyn Turcotte 2012-11-01 07:00:03 PDT
Brady, would you have a minute to check the last patch?
Comment 11 Jocelyn Turcotte 2012-11-01 08:18:10 PDT
Committed r133175: <http://trac.webkit.org/changeset/133175>