Skip to content

Commit bde8c32

Browse files
committed
quic: Fix object lifetime in nested calls
1 parent 2ea1bbb commit bde8c32

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/quic/streams.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,12 @@ class Stream::Outbound final : public MemoryRetainer {
526526
// Always make sure next_pending_ is false when we're done.
527527
auto on_exit = OnScopeLeave([this] { next_pending_ = false; });
528528

529+
// We need to hold a reference to stream and session
530+
// so that it can not go away during the next calls.
531+
BaseObjectPtr<Stream> stream = BaseObjectPtr<Stream>(stream_);
532+
BaseObjectPtr<Session> session =
533+
BaseObjectPtr<Session>(&stream_ ->session());
534+
529535
// The status should never be wait here.
530536
DCHECK_NE(status, bob::Status::STATUS_WAIT);
531537

@@ -534,7 +540,7 @@ class Stream::Outbound final : public MemoryRetainer {
534540
// being asynchronous, our stream is blocking waiting for the data,
535541
// but we have an error! oh no! We need to error the stream.
536542
if (next_pending_) {
537-
stream_->Destroy(
543+
stream->Destroy(
538544
QuicError::ForNgtcp2Error(NGTCP2_INTERNAL_ERROR));
539545
// We do not need to worry about calling MarkErrored in this case
540546
// since we are immediately destroying the stream which will
@@ -553,7 +559,7 @@ class Stream::Outbound final : public MemoryRetainer {
553559
// in the uncommitted queue. We'll resume the stream so that the
554560
// session will try to read from it again.
555561
if (next_pending_) {
556-
stream_->session().ResumeStream(stream_->id());
562+
session->ResumeStream(stream_->id());
557563
}
558564
return;
559565
}
@@ -577,7 +583,7 @@ class Stream::Outbound final : public MemoryRetainer {
577583
// Now that we have data, let's resume the stream so the session will
578584
// pull from it again.
579585
if (next_pending_) {
580-
stream_->session().ResumeStream(stream_->id());
586+
stream->session().ResumeStream(stream_->id());
581587
}
582588
},
583589
bob::OPTIONS_SYNC,
@@ -1406,7 +1412,10 @@ JS_METHOD_IMPL(DataQueueFeeder::Submit) {
14061412
static_cast<char*>(originalStore->Data()) + typedArray->ByteOffset();
14071413
memcpy(backing->Data(), originalData, nread);
14081414
auto& pending = feeder->pendingPulls_.front();
1409-
auto pop = OnScopeLeave([feeder] { feeder->pendingPulls_.pop_front(); });
1415+
auto pop = OnScopeLeave([feeder] {
1416+
if (feeder->pendingPulls_.size() > 0)
1417+
feeder->pendingPulls_.pop_front();
1418+
});
14101419
DataQueue::Vec vec;
14111420
vec.base = static_cast<uint8_t*>(backing->Data());
14121421
vec.len = static_cast<uint64_t>(nread);

0 commit comments

Comments
 (0)