summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2016-10-04 09:10:11 +0000
committerLiong Sauw Ming <ming@teluu.com>2016-10-04 09:10:11 +0000
commit5aeff33c70f16b36b2b08a1169d12d0951630e1c (patch)
treed9a97831227822934b1fe57bcf263ffef2a707e9
parente02afb3d542fb7df6f1e7af7a31e3a64dee0a8a5 (diff)
Fixed #1962: Premature STUN socket destruction when there's an error during STUN server resolution
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5442 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjsip/include/pjsua-lib/pjsua_internal.h2
-rw-r--r--pjsip/src/pjsua-lib/pjsua_core.c10
2 files changed, 12 insertions, 0 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h
index e6cc824e..0827ac8c 100644
--- a/pjsip/include/pjsua-lib/pjsua_internal.h
+++ b/pjsip/include/pjsua-lib/pjsua_internal.h
@@ -374,6 +374,8 @@ typedef struct pjsua_stun_resolve
pj_status_t status; /**< Session status */
pj_sockaddr addr; /**< Result */
pj_stun_sock *stun_sock; /**< Testing STUN sock */
+ pj_bool_t async_wait;/**< Async resolution
+ of STUN entry */
} pjsua_stun_resolve;
/* See also pjsua_vid_win_type_name() */
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index 55af3ad1..3285769d 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -1284,6 +1284,14 @@ static pj_bool_t test_stun_on_status(pj_stun_sock *stun_sock,
(int)sess->srv[sess->idx].slen,
sess->srv[sess->idx].ptr, errmsg));
+ if (op == PJ_STUN_SOCK_BINDING_OP && !sess->async_wait) {
+ /* Just return here, we will destroy the STUN socket and
+ * continue the STUN resolution later in resolve_stun_entry().
+ * For more details, please refer to ticket #19xx.
+ */
+ return PJ_FALSE;
+ }
+
pj_stun_sock_destroy(stun_sock);
sess->stun_sock = NULL;
@@ -1372,6 +1380,7 @@ static void resolve_stun_entry(pjsua_stun_resolve *sess)
/* Use STUN_sock to test this entry */
pj_bzero(&stun_sock_cb, sizeof(stun_sock_cb));
stun_sock_cb.on_status = &test_stun_on_status;
+ sess->async_wait = PJ_FALSE;
status = pj_stun_sock_create(&pjsua_var.stun_cfg, "stunresolve",
pj_AF_INET(), &stun_sock_cb,
NULL, sess, &sess->stun_sock);
@@ -1404,6 +1413,7 @@ static void resolve_stun_entry(pjsua_stun_resolve *sess)
/* Done for now, testing will resume/complete asynchronously in
* stun_sock_cb()
*/
+ sess->async_wait = PJ_TRUE;
return;
}