From 5aeff33c70f16b36b2b08a1169d12d0951630e1c Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Tue, 4 Oct 2016 09:10:11 +0000 Subject: 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 --- pjsip/include/pjsua-lib/pjsua_internal.h | 2 ++ pjsip/src/pjsua-lib/pjsua_core.c | 10 ++++++++++ 2 files changed, 12 insertions(+) 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; } -- cgit v1.2.3