Bug 24263 - [GTK] ref ResourceHandle until we are finished with it
Summary: [GTK] ref ResourceHandle until we are finished with it
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords:
: 24196 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-02-28 11:21 PST by Xan Lopez
Modified: 2009-03-07 12:40 PST (History)
1 user (show)

See Also:


Attachments
refsouphandle.patch (3.73 KB, patch)
2009-02-28 11:23 PST, Xan Lopez
no flags Details | Formatted Diff | Diff
refsouphandlev2.patch (3.74 KB, patch)
2009-02-28 11:27 PST, Xan Lopez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Xan Lopez 2009-02-28 11:21:17 PST
Add a ref to the ResourceHandle in startHttp so we can keep it alive untill all callbacks have been executed, and unref it when soup tells us it's done with the SoupMessage (in finishedCallback). Fixes a number of crashes when calling didReceiveData whould crash because of the handle dying.

Ideally we'd like to do this automatically with RefPtr I guess, but I'm not sure how to apply that here.
Comment 1 Xan Lopez 2009-02-28 11:23:18 PST
Created attachment 28121 [details]
refsouphandle.patch

Patch. And thanks to kov for the joint debugging session! :)
Comment 2 Xan Lopez 2009-02-28 11:27:55 PST
Created attachment 28122 [details]
refsouphandlev2.patch

Slightly improve comment text.
Comment 3 Holger Freyther 2009-02-28 11:55:35 PST
Comment on attachment 28122 [details]
refsouphandlev2.patch

r=me with two strings attached:

  - If possible I would like to see the adopRef in the finishedCallback (after this patch).
  - we need to find out if finishedCallback will always be called or if we just created a memory leak. the consensus on #webkit-gtk was that it is better to leak than to crash (for this release). We need to clean this up after the release...


> @@ -262,30 +262,32 @@ static void finishedCallback(SoupSession *session, SoupMessage* msg, gpointer da
>  
>      ResourceHandleClient* client = handle->client();
>      if (!client)
> -        return;
> +        goto exit;

this goto might be avoided with a RefPtr::adoptRef early on. I'm not quite sure, it would be nice if you could investiage that.


>  
>      d->m_msg = static_cast<SoupMessage*>(g_object_ref(msg));
> +    ref(); // balanced by a deref() in finishedCallback, which should always run

maybe you could move the comment above the line?
>      soup_session_queue_message(session, d->m_msg, finishedCallback, ma
Comment 4 Christian Dywan 2009-02-28 12:31:44 PST
2009-02-28  Xan Lopez  <xan@gnome.org>

        Reviewed by Holger Freyther.

        https://bugs.webkit.org/show_bug.cgi?id=24263
        [GTK] ref ResourceHandle until we are finished with it

        Add a ref to the ResourceHandle in startHttp so we can keep it
        alive untill all callbacks have been executed, and unref it when
        soup tells us it's done with the SoupMessage (in
        finishedCallback). Fixes a number of crashes when calling
        didReceiveData whould crash because of the handle dying.

        * platform/network/soup/ResourceHandleSoup.cpp:
        (WebCore::finishedCallback):
        (WebCore::ResourceHandle::startHttp):

Adjusted the comment and used adoptRef as suggested and discussed on IRC.
Comment 5 Xan Lopez 2009-02-28 15:03:47 PST
*** Bug 24196 has been marked as a duplicate of this bug. ***
Comment 6 Xan Lopez 2009-03-07 12:40:52 PST
Well, since all the points Holger raised were addressed (some by mistake in the same patch :)), I think we can close this.