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 62823ef
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions components/mdns/mdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ static bool _mdns_append_host_list(mdns_out_answer_t **destination, bool flush,
static void _mdns_remap_self_service_hostname(const char *old_hostname, const char *new_hostname);
static esp_err_t mdns_post_custom_action_tcpip_if(mdns_if_t mdns_if, mdns_event_actions_t event_action);

static void _mdns_query_results_free(mdns_result_t *results);

typedef enum {
MDNS_IF_STA = 0,
MDNS_IF_AP = 1,
Expand Down Expand Up @@ -5600,7 +5602,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 +5750,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 +5861,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 +6015,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 +6343,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();
}

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

0 comments on commit 62823ef

Please sign in to comment.