Fix dangling ptr in ReadResponseCallbackWrapper (fixes #3760)

This commit is contained in:
JC Yang 2024-08-05 12:28:17 -04:00 committed by Marshall Greenblatt
parent 9fb397603b
commit b1c7fade27
1 changed files with 7 additions and 4 deletions

View File

@ -213,7 +213,8 @@ class InputStreamReader : public base::RefCountedThreadSafe<InputStreamReader> {
InputStream::SkipCallback skip_callback); InputStream::SkipCallback skip_callback);
static void RunReadCallbackOnJobThread( static void RunReadCallbackOnJobThread(
int bytes_read, int bytes_read,
InputStream::ReadCallback read_callback); InputStream::ReadCallback read_callback,
scoped_refptr<net::IOBuffer> buffer);
std::unique_ptr<InputStream> stream_; std::unique_ptr<InputStream> stream_;
@ -442,8 +443,9 @@ void InputStreamReader::RunReadCallback(int bytes_read) {
DCHECK(!pending_read_callback_.is_null()); DCHECK(!pending_read_callback_.is_null());
job_thread_task_runner_->PostTask( job_thread_task_runner_->PostTask(
FROM_HERE, base::BindOnce(InputStreamReader::RunReadCallbackOnJobThread, FROM_HERE,
bytes_read, std::move(pending_read_callback_))); base::BindOnce(InputStreamReader::RunReadCallbackOnJobThread, bytes_read,
std::move(pending_read_callback_), buffer_));
// Reset callback state. // Reset callback state.
pending_callback_id_ = -1; pending_callback_id_ = -1;
@ -460,7 +462,8 @@ void InputStreamReader::RunSkipCallbackOnJobThread(
// static // static
void InputStreamReader::RunReadCallbackOnJobThread( void InputStreamReader::RunReadCallbackOnJobThread(
int bytes_read, int bytes_read,
InputStream::ReadCallback read_callback) { InputStream::ReadCallback read_callback,
scoped_refptr<net::IOBuffer> buffer) {
std::move(read_callback).Run(bytes_read); std::move(read_callback).Run(bytes_read);
} }