Bug 946733. Simplify turn client ctx lifecycle. r=ekr, martin
authorByron Campen [:bwc] <docfaraday@gmail.com>
Thu, 05 Dec 2013 16:08:54 -0800
changeset 159389 046cf0c4f8587572b631e064261592bc33a8805f
parent 159388 2bb7e7192ced466e7dc05c2853e024cdaf2c7c5c
child 159390 406c304aa64039f36ebe8ef294717bb7d8b8eb84
push id37289
push userrjesup@wgate.com
push dateSun, 08 Dec 2013 04:40:31 +0000
treeherdermozilla-inbound@046cf0c4f858 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersekr, martin
bugs946733
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 946733. Simplify turn client ctx lifecycle. r=ekr, martin
media/mtransport/third_party/nICEr/src/stun/turn_client_ctx.c
--- a/media/mtransport/third_party/nICEr/src/stun/turn_client_ctx.c
+++ b/media/mtransport/third_party/nICEr/src/stun/turn_client_ctx.c
@@ -375,16 +375,38 @@ nr_turn_client_ctx_destroy(nr_turn_clien
     r_log(NR_LOG_TURN, LOG_DEBUG, "TURN(%s): destroy", ctx->label);
 
   /* Cancel frees the rest of our data */
   RFREE(ctx->label);
   ctx->label = 0;
 
   nr_turn_client_cancel(ctx);
 
+  RFREE(ctx->username);
+  ctx->username = 0;
+  r_data_destroy(&ctx->password);
+  RFREE(ctx->nonce);
+  ctx->nonce = 0;
+  RFREE(ctx->realm);
+  ctx->realm = 0;
+
+  /* Destroy the STUN client ctxs */
+  while (!STAILQ_EMPTY(&ctx->stun_ctxs)) {
+    nr_turn_stun_ctx *stun = STAILQ_FIRST(&ctx->stun_ctxs);
+    STAILQ_REMOVE_HEAD(&ctx->stun_ctxs, entry);
+    nr_turn_stun_ctx_destroy(&stun);
+  }
+
+  /* Destroy the permissions */
+  while (!STAILQ_EMPTY(&ctx->permissions)) {
+    nr_turn_permission *perm = STAILQ_FIRST(&ctx->permissions);
+    STAILQ_REMOVE_HEAD(&ctx->permissions, entry);
+    nr_turn_permission_destroy(&perm);
+  }
+
   RFREE(ctx);
 
   return(0);
 }
 
 static int nr_turn_client_connect(nr_turn_client_ctx *ctx)
 {
   int r,_status;
@@ -452,16 +474,18 @@ static void nr_turn_client_connected_cb(
 abort:
   if (_status) {
     nr_turn_client_failed(ctx);
   }
 }
 
 int nr_turn_client_cancel(nr_turn_client_ctx *ctx)
 {
+  nr_turn_stun_ctx *stun = 0;
+
   if (ctx->state == NR_TURN_CLIENT_STATE_CANCELLED ||
       ctx->state == NR_TURN_CLIENT_STATE_FAILED)
     return 0;
 
   if (ctx->label)
     r_log(NR_LOG_TURN, LOG_INFO, "TURN(%s): cancelling", ctx->label);
 
   /* If we are waiting for connect, we need to stop
@@ -477,39 +501,21 @@ int nr_turn_client_cancel(nr_turn_client
          error, we shouldn't cancel. */
       r_log(NR_LOG_TURN, LOG_ERR, "TURN: Couldn't get internal fd");
     }
     else {
       NR_ASYNC_CANCEL(fd, NR_ASYNC_WAIT_WRITE);
     }
   }
 
-  /* Setting these values to 0 isn't strictly necessary, but
-     it protects us in case we double cancel and for
-     some reason bungle the states above in future.*/
-  RFREE(ctx->username);
-  ctx->username = 0;
-  r_data_destroy(&ctx->password);
-  RFREE(ctx->nonce);
-  ctx->nonce = 0;
-  RFREE(ctx->realm);
-  ctx->realm = 0;
-
-  /* Destroy the STUN client ctxs */
-  while (!STAILQ_EMPTY(&ctx->stun_ctxs)) {
-    nr_turn_stun_ctx *stun = STAILQ_FIRST(&ctx->stun_ctxs);
-    STAILQ_REMOVE_HEAD(&ctx->stun_ctxs, entry);
-    nr_turn_stun_ctx_destroy(&stun);
-  }
-
-  /* Destroy the permissions */
-  while (!STAILQ_EMPTY(&ctx->permissions)) {
-    nr_turn_permission *perm = STAILQ_FIRST(&ctx->permissions);
-    STAILQ_REMOVE_HEAD(&ctx->permissions, entry);
-    nr_turn_permission_destroy(&perm);
+  /* Cancel the STUN client ctxs */
+  stun = STAILQ_FIRST(&ctx->stun_ctxs);
+  while (stun) {
+    nr_stun_client_cancel(stun->stun);
+    stun = STAILQ_NEXT(stun, entry);
   }
 
   /* Cancel the timers, if not already cancelled */
   NR_async_timer_cancel(ctx->connected_timer_handle);
   NR_async_timer_cancel(ctx->refresh_timer_handle);
 
   ctx->state = NR_TURN_CLIENT_STATE_CANCELLED;