Index: pjlib-util/src/pjlib-util/resolver.c =================================================================== --- a/pjlib-util/src/pjlib-util/resolver.c (revision 5463) +++ b/pjlib-util/src/pjlib-util/resolver.c (working copy) @@ -849,9 +849,6 @@ /* Check type */ PJ_ASSERT_RETURN(type > 0 && type < 0xFFFF, PJ_EINVAL); - if (p_query) - *p_query = NULL; - /* Build resource key for looking up hash tables */ init_res_key(&key, type, name); @@ -961,6 +958,9 @@ status = transmit_query(resolver, q); if (status != PJ_SUCCESS) { pj_list_push_back(&resolver->query_free_nodes, q); + + if (p_query) + *p_query = NULL; goto on_return; } Index: pjlib-util/src/pjlib-util/srv_resolver.c =================================================================== --- a/pjlib-util/src/pjlib-util/srv_resolver.c (revision 5463) +++ b/pjlib-util/src/pjlib-util/srv_resolver.c (working copy) @@ -187,9 +187,12 @@ has_pending = PJ_TRUE; } if (srv->q_aaaa) { - pj_dns_resolver_cancel_query(srv->q_aaaa, PJ_FALSE); + if (srv->q_aaaa != (pj_dns_async_query*)0x1) { + /* It is not the dummy query place holder */ + pj_dns_resolver_cancel_query(srv->q_aaaa, PJ_FALSE); + has_pending = PJ_TRUE; + } srv->q_aaaa = NULL; - has_pending = PJ_TRUE; } } @@ -485,12 +488,22 @@ srv->common.type = PJ_DNS_TYPE_A; srv->common_aaaa.type = PJ_DNS_TYPE_AAAA; srv->parent = query_job; + srv->q_a = NULL; + srv->q_aaaa = NULL; status = PJ_SUCCESS; /* Start DNA A record query */ if ((query_job->option & PJ_DNS_SRV_RESOLVE_AAAA_ONLY) == 0) { + if ((query_job->option & PJ_DNS_SRV_RESOLVE_AAAA) != 0) { + /* If there will be DNS AAAA query too, let's setup a dummy one + * here, otherwise app callback may be called immediately (before + * DNS AAAA query is sent) when DNS A record is available in the + * cache. + */ + srv->q_aaaa = (pj_dns_async_query*)0x1; + } status = pj_dns_resolver_start_query(query_job->resolver, &srv->target_name, PJ_DNS_TYPE_A, 0, Index: pjsip/src/pjsip/sip_resolve.c =================================================================== --- a/pjsip/src/pjsip/sip_resolve.c (revision 5463) +++ b/pjsip/src/pjsip/sip_resolve.c (working copy) @@ -441,7 +441,7 @@ * DNS AAAA query is sent) when DNS A record is available in the * cache. */ - if (af == pj_AF_UNSPEC()) + if (af != pj_AF_INET()) query->object6 = (pj_dns_async_query*)0x1; status = pj_dns_resolver_start_query(resolver->res, @@ -452,7 +452,7 @@ } /* Resolve DNS AAAA record if address family is not fixed to IPv4 */ - if (af != pj_AF_INET()) { + if (status == PJ_SUCCESS && af != pj_AF_INET()) { status = pj_dns_resolver_start_query(resolver->res, &query->naptr[0].name, PJ_DNS_TYPE_AAAA, 0, @@ -530,9 +530,9 @@ ++srv->count; } + } - } else { - + if (status != PJ_SUCCESS) { char errmsg[PJ_ERR_MSG_SIZE]; /* Log error */ @@ -593,9 +593,9 @@ ++srv->count; } + } - } else { - + if (status != PJ_SUCCESS) { char errmsg[PJ_ERR_MSG_SIZE]; /* Log error */