diff --git a/media/mtransport/nricectx.cpp b/media/mtransport/nricectx.cpp index 99974cf37545..868fb1ffad6a 100644 --- a/media/mtransport/nricectx.cpp +++ b/media/mtransport/nricectx.cpp @@ -540,11 +540,12 @@ NrIceCtx::SetStream(size_t index, NrIceMediaStream* stream) { streams_.resize(index + 1); } - if (streams_[index]) { - streams_[index]->Close(); - } - + RefPtr oldStream(streams_[index]); streams_[index] = stream; + + if (oldStream) { + oldStream->Close(); + } } std::string NrIceCtx::ufrag() const { diff --git a/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c b/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c index 11ae12ab9429..cc68b2e96db9 100644 --- a/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c +++ b/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c @@ -259,6 +259,13 @@ int nr_ice_candidate_destroy(nr_ice_candidate **candp) cand=*candp; + if (cand->state == NR_ICE_CAND_STATE_INITIALIZING) { + /* Make sure the ICE ctx isn't still waiting around for this candidate + * to init. */ + cand->state=NR_ICE_CAND_STATE_FAILED; + cand->done_cb(0,0,cand->cb_arg); + } + switch(cand->type){ case HOST: break; diff --git a/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c b/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c index 6249aae80162..8eb7da6f814a 100644 --- a/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c +++ b/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c @@ -405,6 +405,11 @@ static void nr_ice_ctx_destroy_cb(NR_SOCKET s, int how, void *cb_arg) int i; nr_ice_stun_id *id1,*id2; + STAILQ_FOREACH_SAFE(s1, &ctx->streams, entry, s2){ + STAILQ_REMOVE(&ctx->streams,s1,nr_ice_media_stream_,entry); + nr_ice_media_stream_destroy(&s1); + } + RFREE(ctx->label); RFREE(ctx->stun_servers); @@ -426,11 +431,6 @@ static void nr_ice_ctx_destroy_cb(NR_SOCKET s, int how, void *cb_arg) RFREE(ctx->pwd); RFREE(ctx->ufrag); - STAILQ_FOREACH_SAFE(s1, &ctx->streams, entry, s2){ - STAILQ_REMOVE(&ctx->streams,s1,nr_ice_media_stream_,entry); - nr_ice_media_stream_destroy(&s1); - } - STAILQ_FOREACH_SAFE(id1, &ctx->ids, entry, id2){ STAILQ_REMOVE(&ctx->ids,id1,nr_ice_stun_id_,entry); RFREE(id1);