Bug 942950 - Avoid calling done_cb in the wrong order, or multiple times. r=ekr,r=abr, a=abillings
authorByron Campen [:bwc] <docfaraday@gmail.com>
Thu, 12 Dec 2013 13:58:02 -0800
changeset 167790 b45852a5f6dfcf8b8053788ee6c798ac18326833
parent 167789 860046a44b126505533571628e06776cd8ec23c0
child 167791 fa4b83484b568fd9719ea92d189f9bbbd5fd6300
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersekr, abr, abillings
bugs942950
milestone27.0
Bug 942950 - Avoid calling done_cb in the wrong order, or multiple times. r=ekr,r=abr, a=abillings
media/mtransport/third_party/nICEr/src/ice/ice_candidate.c
--- a/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c
@@ -727,30 +727,31 @@ static void nr_ice_turn_allocated_cb(NR_
           ABORT(r);
 
         r_log(LOG_ICE,LOG_DEBUG,"ICE(%s)/CAND(%s): new relay base=%s addr=%s", cand->ctx->label, cand->label, cand->base.as_string, cand->addr.as_string);
 
         RFREE(cand->label);
         cand->label=label;
         cand->state=NR_ICE_CAND_STATE_INITIALIZED;
 
-        /* Execute the ready callback */
-        cand->done_cb(0,0,cand->cb_arg);
-
         /* We also need to activate the associated STUN candidate */
         if(cand->u.relayed.srvflx_candidate){
           nr_ice_candidate *cand2=cand->u.relayed.srvflx_candidate;
 
           if (r=nr_turn_client_get_mapped_address(cand->u.relayed.turn, &cand2->addr))
             ABORT(r);
 
           cand2->state=NR_ICE_CAND_STATE_INITIALIZED;
           cand2->done_cb(0,0,cand2->cb_arg);
         }
 
+        /* Execute the ready callback */
+        cand->done_cb(0,0,cand->cb_arg);
+        cand = 0;
+
         break;
 
     case NR_TURN_CLIENT_STATE_FAILED:
     case NR_TURN_CLIENT_STATE_CANCELLED:
       r_log(NR_LOG_TURN, LOG_WARNING,
             "ICE-CANDIDATE(%s): nr_turn_allocated_cb called with state %d",
             cand->label, turn->state);
       /* This failed, so go to the next TURN server if there is one */
@@ -759,26 +760,28 @@ static void nr_ice_turn_allocated_cb(NR_
     default:
       assert(0); /* should never happen */
       ABORT(R_INTERNAL);
     }
 
     _status=0;
   abort:
     if(_status){
-      r_log(NR_LOG_TURN, LOG_WARNING,
-            "ICE-CANDIDATE(%s): nr_turn_allocated_cb failed", cand->label);
-      cand->state=NR_ICE_CAND_STATE_FAILED;
-      cand->done_cb(0,0,cand->cb_arg);
+      if (cand) {
+        r_log(NR_LOG_TURN, LOG_WARNING,
+              "ICE-CANDIDATE(%s): nr_turn_allocated_cb failed", cand->label);
+        cand->state=NR_ICE_CAND_STATE_FAILED;
+        cand->done_cb(0,0,cand->cb_arg);
 
-      if(cand->u.relayed.srvflx_candidate){
-        nr_ice_candidate *cand2=cand->u.relayed.srvflx_candidate;
+        if(cand->u.relayed.srvflx_candidate){
+          nr_ice_candidate *cand2=cand->u.relayed.srvflx_candidate;
 
-        cand2->state=NR_ICE_CAND_STATE_FAILED;
-        cand2->done_cb(0,0,cand2->cb_arg);
+          cand2->state=NR_ICE_CAND_STATE_FAILED;
+          cand2->done_cb(0,0,cand2->cb_arg);
+        }
       }
     }
   }
 #endif /* USE_TURN */
 
 /* Format the candidate attribute as per ICE S 15.1 */
 int nr_ice_format_candidate_attribute(nr_ice_candidate *cand, char *attr, int maxlen)
   {