Bug 1149298 - Part 2: When destroying a candidate, ensure that the ice_ctx doesn't continue waiting for it to init. r=drno, a=lmandel
authorByron Campen [:bwc] <docfaraday@gmail.com>
Mon, 30 Mar 2015 15:22:28 -0700
changeset 267147 021bc6e975d9f8d3fdf7ef83d6ec86c885a32e99
parent 267146 95e4109eeb365e3f440ba4660c248abee000aa62
child 267148 3e48f6649975ed92f5f052c412f37e9e61848254
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno, lmandel
bugs1149298
milestone39.0a2
Bug 1149298 - Part 2: When destroying a candidate, ensure that the ice_ctx doesn't continue waiting for it to init. r=drno, a=lmandel
media/mtransport/nricectx.cpp
media/mtransport/third_party/nICEr/src/ice/ice_candidate.c
media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
--- a/media/mtransport/nricectx.cpp
+++ b/media/mtransport/nricectx.cpp
@@ -535,21 +535,22 @@ NrIceCtx::CreateStream(const std::string
 }
 
 void
 NrIceCtx::SetStream(size_t index, NrIceMediaStream* stream) {
   if (index >= streams_.size()) {
     streams_.resize(index + 1);
   }
 
-  if (streams_[index]) {
-    streams_[index]->Close();
+  RefPtr<NrIceMediaStream> oldStream(streams_[index]);
+  streams_[index] = stream;
+
+  if (oldStream) {
+    oldStream->Close();
   }
-
-  streams_[index] = stream;
 }
 
 std::string NrIceCtx::ufrag() const {
   return ctx_->ufrag;
 }
 
 std::string NrIceCtx::pwd() const {
   return ctx_->pwd;
--- a/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c
@@ -254,16 +254,23 @@ int nr_ice_candidate_destroy(nr_ice_cand
   {
     nr_ice_candidate *cand=0;
 
     if(!candp || !*candp)
       return(0);
 
     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;
 #ifdef USE_TURN
       case RELAYED:
         if (cand->u.relayed.turn_handle)
           nr_ice_socket_deregister(cand->isock, cand->u.relayed.turn_handle);
         nr_turn_client_ctx_destroy(&cand->u.relayed.turn);
--- a/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
@@ -400,16 +400,21 @@ int nr_ice_ctx_create(char *label, UINT4
 static void nr_ice_ctx_destroy_cb(NR_SOCKET s, int how, void *cb_arg)
   {
     nr_ice_ctx *ctx=cb_arg;
     nr_ice_foundation *f1,*f2;
     nr_ice_media_stream *s1,*s2;
     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);
 
     RFREE(ctx->local_addrs);
 
     for (i = 0; i < ctx->turn_server_ct; i++) {
         RFREE(ctx->turn_servers[i].username);
@@ -421,21 +426,16 @@ static void nr_ice_ctx_destroy_cb(NR_SOC
     while(f1){
       f2=STAILQ_NEXT(f1,entry);
       RFREE(f1);
       f1=f2;
     }
     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);
     }
 
     nr_resolver_destroy(&ctx->resolver);
     nr_interface_prioritizer_destroy(&ctx->interface_prioritizer);
     nr_socket_wrapper_factory_destroy(&ctx->turn_tcp_socket_wrapper);