Skip to content
Permalink
Browse files
Capture WeakPtr to CachedResourceClient in lambdas in CachedRawResour…
…ce::didAddClient()

https://bugs.webkit.org/show_bug.cgi?id=240828
<rdar://93781799>

Reviewed by Alex Christensen.

Capture WeakPtr to CachedResourceClient in lambdas in CachedRawResource::didAddClient()
instead of a raw pointer, for hardening.

* Source/WebCore/loader/cache/CachedRawResource.cpp:
(WebCore::iterateRedirects):
(WebCore::CachedRawResource::didAddClient):

Canonical link: https://commits.webkit.org/250896@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294692 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed May 23, 2022
1 parent 9c4deed commit e5db10363bb2d1d4945a25944df47310e6ca8ad5
Showing 1 changed file with 8 additions and 6 deletions.
@@ -150,9 +150,11 @@ static void iterateRedirects(CachedResourceHandle<CachedRawResource>&& handle, C
if (!handle->hasClient(client) || redirectsInReverseOrder.isEmpty())
return completionHandler({ });
auto redirectPair = redirectsInReverseOrder.takeLast();
client.redirectReceived(*handle, WTFMove(redirectPair.first), WTFMove(redirectPair.second), [handle = WTFMove(handle), client = &client, redirectsInReverseOrder = WTFMove(redirectsInReverseOrder), completionHandler = WTFMove(completionHandler)] (ResourceRequest&&) mutable {
client.redirectReceived(*handle, WTFMove(redirectPair.first), WTFMove(redirectPair.second), [handle = WTFMove(handle), client = WeakPtr { client }, redirectsInReverseOrder = WTFMove(redirectsInReverseOrder), completionHandler = WTFMove(completionHandler)] (ResourceRequest&&) mutable {
// Ignore the new request because we can't do anything with it.
// We're just replying a redirect chain that has already happened.
if (!client)
return completionHandler({ });
iterateRedirects(WTFMove(handle), *client, WTFMove(redirectsInReverseOrder), WTFMove(completionHandler));
});
}
@@ -167,19 +169,19 @@ void CachedRawResource::didAddClient(CachedResourceClient& c)
const auto& pair = m_redirectChain[redirectCount - i - 1];
redirectsInReverseOrder.uncheckedAppend(std::make_pair(pair.m_request, pair.m_redirectResponse));
}
iterateRedirects(CachedResourceHandle<CachedRawResource>(this), client, WTFMove(redirectsInReverseOrder), [this, protectedThis = CachedResourceHandle<CachedRawResource>(this), client = &client] (ResourceRequest&&) mutable {
if (!hasClient(*client))
iterateRedirects(CachedResourceHandle<CachedRawResource>(this), client, WTFMove(redirectsInReverseOrder), [this, protectedThis = CachedResourceHandle<CachedRawResource>(this), client = WeakPtr { client }] (ResourceRequest&&) mutable {
if (!client || !hasClient(*client))
return;
auto responseProcessedHandler = [this, protectedThis = WTFMove(protectedThis), client] {
if (!hasClient(*client))
if (!client || !hasClient(*client))
return;
if (m_data) {
m_data->forEachSegmentAsSharedBuffer([&](auto&& buffer) {
if (hasClient(*client))
if (!client || hasClient(*client))
client->dataReceived(*this, buffer);
});
}
if (!hasClient(*client))
if (!client || !hasClient(*client))
return;
CachedResource::didAddClient(*client);
};

0 comments on commit e5db103

Please sign in to comment.