<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GTK] Crash in WebProcess when loading large content with custom URI schemes"
   href="https://bugs.webkit.org/show_bug.cgi?id=144262#c10">Comment # 10</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GTK] Crash in WebProcess when loading large content with custom URI schemes"
   href="https://bugs.webkit.org/show_bug.cgi?id=144262">bug 144262</a>
              from <span class="vcard"><a class="email" href="mailto:mario&#64;webkit.org" title="Mario Sanchez Prada &lt;mario&#64;webkit.org&gt;"> <span class="fn">Mario Sanchez Prada</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=144262#c9">comment #9</a>)
<span class="quote">&gt; [...]
&gt; &gt; I think we shouldn't even call data-&gt;releaseTask() when we have a stream. I would use an early return instead, something like:
&gt; &gt; 
&gt; &gt; if (!data-&gt;stream) {
&gt; &gt;     // Failed while reading the stream, the task was already completed by didLoadData().
&gt; &gt;     return;
&gt; &gt; }
&gt; &gt; 
&gt; &gt; GRefPtr&lt;GTask&gt; task = data-&gt;releaseTask();
&gt; &gt; ASSERT(task.get());
&gt; &gt; g_task_return_new_error....
&gt; 
&gt; That was my initial version, but I was unsure about doing it and in the end
&gt; preferred to do it always and assert task or !task depending on the case.
&gt; 
&gt; Anyway, I will change it in the next patch</span >

Just a quick heads-up after a conversation on IRC with Carlos: we can't really early return because we still need to remove the data from the m_customProtocolMap hash table, and also, perhaps ASSERT() task and !task depending on the case would not be a too bad thing either... so we kind of settled on the following code for didFailError():

    void CustomProtocolManagerImpl::didFailWithError(uint64_t customProtocolID, const WebCore::ResourceError&amp; error)
    {
        WebSoupRequestAsyncData* data = m_customProtocolMap.get(customProtocolID);
        ASSERT(data);

        // Either we haven't started reading the stream yet, in which case we need to complete the
        // task first, or we failed reading it and the task was already completed by didLoadData().
        ASSERT(!data-&gt;stream || !data-&gt;task);

        if (!data-&gt;stream) {
            GRefPtr&lt;GTask&gt; task = data-&gt;releaseTask();
            ASSERT(task.get());
            g_task_return_new_error(task.get(), g_quark_from_string(error.domain().utf8().data()),
                error.errorCode(), &quot;%s&quot;, error.localizedDescription().utf8().data());
        }

        m_customProtocolMap.remove(customProtocolID);
    }

Still, I need to write the unit test in a proper way, but I thought I would share this before, because previous comments could be confusing.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>