Skip to content

Commit

Permalink
Bug 814470 - Fix a leak when channel setup in AsyncFetchAndSetIconFro…
Browse files Browse the repository at this point in the history
…mNetwork fails by not tracking the channel in the first place and thus avoiding a circular references. r=mak
  • Loading branch information
nmaier committed Nov 27, 2012
1 parent e0d26ab commit ffca6c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
24 changes: 10 additions & 14 deletions toolkit/components/places/AsyncFaviconHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,6 @@ AsyncFetchAndSetIconFromNetwork::AsyncFetchAndSetIconFromNetwork(

AsyncFetchAndSetIconFromNetwork::~AsyncFetchAndSetIconFromNetwork()
{
nsCOMPtr<nsIThread> thread;
(void)NS_GetMainThread(getter_AddRefs(thread));
if (mChannel) {
(void)NS_ProxyRelease(thread, mChannel, true);
}
}

NS_IMETHODIMP
Expand All @@ -570,22 +565,20 @@ AsyncFetchAndSetIconFromNetwork::Run()
nsCOMPtr<nsIURI> iconURI;
nsresult rv = NS_NewURI(getter_AddRefs(iconURI), mIcon.spec);
NS_ENSURE_SUCCESS(rv, rv);
rv = NS_NewChannel(getter_AddRefs(mChannel), iconURI);
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel), iconURI);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInterfaceRequestor> listenerRequestor =
do_QueryInterface(reinterpret_cast<nsISupports*>(this));
NS_ENSURE_STATE(listenerRequestor);
rv = mChannel->SetNotificationCallbacks(listenerRequestor);
rv = channel->SetNotificationCallbacks(listenerRequestor);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(mChannel);
nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(channel);
if (pbChannel) {
rv = pbChannel->SetPrivate(mFaviconLoadPrivate);
NS_ENSURE_SUCCESS(rv, rv);
}
rv = mChannel->AsyncOpen(this, nullptr);
NS_ENSURE_SUCCESS(rv, rv);

return NS_OK;
return channel->AsyncOpen(this, nullptr);
}

NS_IMETHODIMP
Expand Down Expand Up @@ -629,7 +622,6 @@ AsyncFetchAndSetIconFromNetwork::AsyncOnChannelRedirect(
, nsIAsyncVerifyRedirectCallback *cb
)
{
mChannel = newChannel;
(void)cb->OnRedirectVerifyCallback(NS_OK);
return NS_OK;
}
Expand Down Expand Up @@ -670,7 +662,11 @@ AsyncFetchAndSetIconFromNetwork::OnStopRequest(nsIRequest* aRequest,
return NS_OK;
}

mIcon.expiration = GetExpirationTimeFromChannel(mChannel);
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
// aRequest should always QI to nsIChannel.
// See AsyncFetchAndSetIconFromNetwork::Run()
MOZ_ASSERT(channel);
mIcon.expiration = GetExpirationTimeFromChannel(channel);

rv = OptimizeIconSize(mIcon, favicons);
NS_ENSURE_SUCCESS(rv, rv);
Expand Down
1 change: 0 additions & 1 deletion toolkit/components/places/AsyncFaviconHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ class AsyncFetchAndSetIconFromNetwork : public AsyncFaviconHelperBase
protected:
IconData mIcon;
PageData mPage;
nsCOMPtr<nsIChannel> mChannel;
const bool mFaviconLoadPrivate;
};

Expand Down

0 comments on commit ffca6c1

Please sign in to comment.