From 2396bbe185b1dc51d4e5d9ce0326b2e066b32dc7 Mon Sep 17 00:00:00 2001 From: Kenichi Ishibashi Date: Sat, 6 May 2023 08:13:31 +0800 Subject: [PATCH] Check callback availability in SpdyProxyClientSocket::RunWriteCallback OnClose() could consume `write_callback_` so it may not be available when RunWriteCallback() is invoked. Bug: 1428820 Change-Id: I9a5ade62d67f5bf15e12d0915d1ad6098657ffd4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4437791 Code-Coverage: Findit Reviewed-by: Adam Rice Commit-Queue: Kenichi Ishibashi Cr-Commit-Position: refs/heads/main@{#1131689} --- src/net/spdy/spdy_proxy_client_socket.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/net/spdy/spdy_proxy_client_socket.cc b/src/net/spdy/spdy_proxy_client_socket.cc index 62877bba9f..3cfa333731 100644 --- a/src/net/spdy/spdy_proxy_client_socket.cc +++ b/src/net/spdy/spdy_proxy_client_socket.cc @@ -277,10 +277,11 @@ int SpdyProxyClientSocket::GetLocalAddress(IPEndPoint* address) const { } void SpdyProxyClientSocket::RunWriteCallback(int result) { - CHECK(write_callback_); - base::WeakPtr weak_ptr = weak_factory_.GetWeakPtr(); - std::move(write_callback_).Run(result); + // `write_callback_` might be consumed by OnClose(). + if (write_callback_) { + std::move(write_callback_).Run(result); + } if (!weak_ptr) { // `this` was already destroyed while running `write_callback_`. Must // return immediately without touching any field member.