Commit 85254465 authored by Ghislain MARY's avatar Ghislain MARY

Do not free addrinfo when destroying the resolver.

parent d1659e38
......@@ -226,10 +226,10 @@ struct addrinfo * belle_sip_ip_address_to_addrinfo(const char *ipaddress, int po
static void belle_sip_resolver_context_destroy(belle_sip_resolver_context_t *ctx){
/* Do not free ctx->ai with freeaddrinfo(). Let the caller do it, otherwise
it will not be able to use it after the resolver has been destroyed. */
if (ctx->name)
belle_sip_free(ctx->name);
if (ctx->ai)
freeaddrinfo(ctx->ai);
if (ctx->R)
dns_res_close(ctx->R);
if (ctx->hosts)
......
......@@ -33,8 +33,7 @@ typedef struct endpoint {
belle_sip_stack_t* stack;
long unsigned int resolver_id;
int resolve_done;
int resolve_successful;
struct sockaddr_storage ss;
struct addrinfo *result;
} endpoint_t;
static unsigned int wait_for(belle_sip_stack_t *stack, int *current_value, int expected_value, int timeout) {
......@@ -58,8 +57,10 @@ static endpoint_t* create_endpoint(void) {
static void reset_endpoint(endpoint_t *endpoint) {
endpoint->resolver_id = 0;
endpoint->resolve_done = 0;
endpoint->resolve_successful = 0;
memset(&endpoint->ss, 0, sizeof(endpoint->ss));
if (endpoint->result) {
freeaddrinfo(endpoint->result);
endpoint->result = NULL;
}
}
static void destroy_endpoint(endpoint_t *endpoint) {
......@@ -72,8 +73,7 @@ static void resolve_done(void *data, const char *name, struct addrinfo *res) {
endpoint_t *client = (endpoint_t *)data;
client->resolve_done = 1;
if (res) {
client->resolve_successful = 1;
memcpy(&client->ss, res->ai_addr, sizeof(client->ss));
client->result = res;
}
}
......@@ -90,9 +90,9 @@ static void resolve(void) {
peer_name = IPV4_SIP_DOMAIN;
client->resolver_id = belle_sip_resolve(client->stack, peer_name, peer_port, family, resolve_done, client, belle_sip_stack_get_main_loop(client->stack));
CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, 2000));
CU_ASSERT_EQUAL(client->resolve_successful, 1);
if (client->resolve_successful) {
struct sockaddr_in *sock_in = (struct sockaddr_in *)&client->ss;
CU_ASSERT_PTR_NOT_EQUAL(client->result, NULL);
if (client->result) {
struct sockaddr_in *sock_in = (struct sockaddr_in *)client->result->ai_addr;
CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), peer_port);
ai = belle_sip_ip_address_to_addrinfo(IPV4_SIP_IP, peer_port);
if (ai) {
......@@ -106,9 +106,9 @@ static void resolve(void) {
peer_name = IPV6_SIP_DOMAIN;
client->resolver_id = belle_sip_resolve(client->stack, peer_name, peer_port, family, resolve_done, client, belle_sip_stack_get_main_loop(client->stack));
CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, 2000));
CU_ASSERT_EQUAL(client->resolve_successful, 1);
if (client->resolve_successful) {
struct sockaddr_in6 *sock_in6 = (struct sockaddr_in6 *)&client->ss;
CU_ASSERT_PTR_NOT_EQUAL(client->result, NULL);
if (client->result) {
struct sockaddr_in6 *sock_in6 = (struct sockaddr_in6 *)client->result->ai_addr;
CU_ASSERT_EQUAL(ntohs(sock_in6->sin6_port), peer_port);
ai = belle_sip_ip_address_to_addrinfo(IPV6_SIP_IP, peer_port);
if (ai) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment