Skip to content

Commit

Permalink
dns-server: fix race condition issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Aug 9, 2020
1 parent 1923271 commit a9829f6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dns_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ static void _dns_server_select_possible_ipaddress(struct dns_request *request)

/* Return the most likely correct IP address */
/* Returns the IP with the most hits, or the last returned record is considered to be the most likely correct. */
pthread_mutex_lock(&request->ip_map_lock);
hash_for_each_safe(request->ip_map, bucket, tmp, addr_map, node)
{
if (addr_map->addr_type != request->qtype) {
Expand All @@ -896,6 +897,7 @@ static void _dns_server_select_possible_ipaddress(struct dns_request *request)
maxhit_addr_map = addr_map;
}
}
pthread_mutex_unlock(&request->ip_map_lock);

if (maxhit_addr_map && maxhit > 1) {
selected_addr_map = maxhit_addr_map;
Expand Down Expand Up @@ -966,11 +968,13 @@ static void _dns_server_request_release_complete(struct dns_request *request, in
_dns_server_request_complete(request);
}

pthread_mutex_lock(&request->ip_map_lock);
hash_for_each_safe(request->ip_map, bucket, tmp, addr_map, node)
{
hash_del(&addr_map->node);
free(addr_map);
}
pthread_mutex_unlock(&request->ip_map_lock);

_dns_server_delete_request(request);
}
Expand Down

0 comments on commit a9829f6

Please sign in to comment.