Skip to content

Commit

Permalink
fix(mdns): add lock for some common apis
Browse files Browse the repository at this point in the history
  • Loading branch information
zwx1995esp committed Mar 13, 2024
1 parent 46a6244 commit 7a078e0
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions components/mdns/mdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -5600,7 +5600,7 @@ void mdns_free(void)
free(h->proto);
vSemaphoreDelete(h->done_semaphore);
if (h->result) {
mdns_query_results_free(h->result);
_mdns_query_results_free(h->result);
}
free(h);
}
Expand Down Expand Up @@ -5748,7 +5748,11 @@ esp_err_t mdns_delegate_hostname_set_address(const char *hostname, const mdns_ip

bool mdns_hostname_exists(const char *hostname)
{
return _hostname_is_ours(hostname);
bool ret = false;
MDNS_SERVICE_LOCK();
ret = _hostname_is_ours(hostname);
MDNS_SERVICE_UNLOCK();
return ret;
}

esp_err_t mdns_instance_name_set(const char *instance)
Expand Down Expand Up @@ -5855,13 +5859,21 @@ esp_err_t mdns_service_add(const char *instance, const char *service, const char

bool mdns_service_exists(const char *service_type, const char *proto, const char *hostname)
{
return _mdns_get_service_item(service_type, proto, hostname) != NULL;
bool ret = false;
MDNS_SERVICE_LOCK();
ret = _mdns_get_service_item(service_type, proto, hostname) != NULL;
MDNS_SERVICE_UNLOCK();
return ret;
}

bool mdns_service_exists_with_instance(const char *instance, const char *service_type, const char *proto,
const char *hostname)
{
return _mdns_get_service_item_instance(instance, service_type, proto, hostname) != NULL;
bool ret = false;
MDNS_SERVICE_LOCK();
ret = _mdns_get_service_item_instance(instance, service_type, proto, hostname) != NULL;
MDNS_SERVICE_UNLOCK();
return ret;
}

static mdns_txt_item_t *_copy_mdns_txt_items(mdns_txt_linked_item_t *items, uint8_t **txt_value_len, size_t *txt_count)
Expand Down Expand Up @@ -6001,7 +6013,7 @@ static mdns_result_t *_mdns_lookup_service(const char *instance, const char *ser
}
return results;
handle_error:
mdns_query_results_free(results);
_mdns_query_results_free(results);
return NULL;
}

Expand Down Expand Up @@ -6329,8 +6341,14 @@ esp_err_t mdns_service_remove_all(void)
/*
* MDNS QUERY
* */

void mdns_query_results_free(mdns_result_t *results)
{
MDNS_SERVICE_LOCK();
_mdns_query_results_free(results);
MDNS_SERVICE_UNLOCK();
}

void _mdns_query_results_free(mdns_result_t *results)
{
mdns_result_t *r;
mdns_ip_addr_t *a;
Expand Down

0 comments on commit 7a078e0

Please sign in to comment.