Fix memory errors that QUICHE uncovered with MoqtSession. I was able to repro the failure in OSS Quiche, and fix it, although there are apparently other issues with using bazel's memory sanitizer with GoogleTest (which cause most other Quiche unit tests to fail for the same reason). PiperOrigin-RevId: 867257330
diff --git a/quiche/quic/moqt/moqt_session.cc b/quiche/quic/moqt/moqt_session.cc index bbe5b34..05dafcf 100644 --- a/quiche/quic/moqt/moqt_session.cc +++ b/quiche/quic/moqt/moqt_session.cc
@@ -303,12 +303,17 @@ std::unique_ptr<MoqtNamespaceSubscriberStream> state = std::make_unique<MoqtNamespaceSubscriberStream>( &framer_, next_request_id_, - [this, prefix]() { - if (!is_closing_) { - outgoing_subscribe_namespace_.UnsubscribeNamespace(prefix); + [session_weak_ptr = GetWeakPtr(), this, pref = prefix]() { + if (!session_weak_ptr.IsValid() || is_closing_) { + return; } + outgoing_subscribe_namespace_.UnsubscribeNamespace(pref); }, - [this](MoqtError error, absl::string_view reason) { + [session_weak_ptr = GetWeakPtr(), this](MoqtError error, + absl::string_view reason) { + if (!session_weak_ptr.IsValid() || is_closing_) { + return; + } Error(error, reason); }, std::move(response_callback));