Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure QuicChromiumPacketWriter isn't still tracked when deleted. #4691

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion net/quic/quic_chromium_packet_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ bool QuicChromiumPacketReader::ProcessMultiplePacketReadResult(int result) {
quic::QuicSocketAddress quick_peer_address =
ToQuicSocketAddress(peer_address);

auto self = weak_factory_.GetWeakPtr();
struct Socket::ReadPacketResult* read_packet = read_results_.packets;
for (int p = 0; p < read_results_.result; ++p, ++read_packet) {
if (read_packet->result <= 0) {
continue;
}
quic::QuicReceivedPacket packet(read_packet->buffer, read_packet->result,
clock_->ApproximateNow());
auto self = weak_factory_.GetWeakPtr();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't matter where you call this. Does the weak pointer need to be invalidated before the QuicChromiumPacketReader instance gets destroyed? If you so, you can call weak_factory_.InvalidateWeakPtrs().

Every time the weak pointer is treated like a bool, the WeakReference is checked to see if it's still valid.

if (!(visitor_->OnPacket(packet, quick_local_address, quick_peer_address) &&
self)) {
return false;
Expand Down
20 changes: 15 additions & 5 deletions net/third_party/quiche/src/quiche/quic/core/quic_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void QuicConnection::InstallInitialCrypters(QuicConnectionId connection_id) {

QuicConnection::~QuicConnection() {
QUICHE_DCHECK_GE(stats_.max_egress_mtu, long_term_mtu_);
if (owns_writer_) {
if (writer_ != nullptr && owns_writer_) {
delete writer_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it do owns_writer_ = false; here as well just in case ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered doing that, but elsewhere that boolean is only ever used when the pointer is not nullptr.

}
ClearQueuedPackets();
Expand Down Expand Up @@ -2439,7 +2439,7 @@ QuicPacketNumber QuicConnection::GetLeastUnacked() const {
}

bool QuicConnection::HandleWriteBlocked() {
if (!writer_->IsWriteBlocked()) {
if (writer_ != nullptr && !writer_->IsWriteBlocked()) {
return false;
}

Expand Down Expand Up @@ -2808,12 +2808,14 @@ void QuicConnection::ProcessUdpPacket(const QuicSocketAddress& self_address,
}

void QuicConnection::OnBlockedWriterCanWrite() {
writer_->SetWritable();
OnCanWrite();
if (writer_) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny style inconsistency nitpick: Above you are writing out writer != nullptr but here you do a simple boolean check. I don't think it matters either way, but would be good to keep consistent style.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the pre-existing pattern already used elsewhere in this file for consistency

writer_->SetWritable();
OnCanWrite();
}
}

void QuicConnection::OnCanWrite() {
if (!connected_) {
if (!connected_ || !writer_) {
return;
}
if (writer_->IsWriteBlocked()) {
Expand Down Expand Up @@ -6911,6 +6913,10 @@ bool QuicConnection::MigratePath(const QuicSocketAddress& self_address,
QUICHE_DCHECK(perspective_ == Perspective::IS_CLIENT);
if (!connected_) {
if (owns_writer) {
if (writer_ == writer) {
writer_ = nullptr;
owns_writer_ = false;
}
delete writer;
}
return false;
Expand All @@ -6921,6 +6927,10 @@ bool QuicConnection::MigratePath(const QuicSocketAddress& self_address,
if (connection_migration_use_new_cid_) {
if (!UpdateConnectionIdsOnMigration(self_address, peer_address)) {
if (owns_writer) {
if (writer_ == writer) {
writer_ = nullptr;
owns_writer_ = false;
}
delete writer;
}
return false;
Expand Down
Loading