mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-06-26 09:51:34 +02:00
fix(mdns): Fix API races when removing all services
Fixes **API race issue** (described in 8a690503
) for API
mdns_service_remove_all()
This commit is contained in:
@ -5148,8 +5148,6 @@ static void _mdns_free_action(mdns_action_t *action)
|
|||||||
*/
|
*/
|
||||||
static void _mdns_execute_action(mdns_action_t *action)
|
static void _mdns_execute_action(mdns_action_t *action)
|
||||||
{
|
{
|
||||||
mdns_srv_item_t *a = NULL;
|
|
||||||
|
|
||||||
switch (action->type) {
|
switch (action->type) {
|
||||||
case ACTION_SYSTEM_EVENT:
|
case ACTION_SYSTEM_EVENT:
|
||||||
perform_event_action(action->data.sys_event.interface, action->data.sys_event.event_action);
|
perform_event_action(action->data.sys_event.interface, action->data.sys_event.event_action);
|
||||||
@ -5169,19 +5167,6 @@ static void _mdns_execute_action(mdns_action_t *action)
|
|||||||
_mdns_server->instance = action->data.instance;
|
_mdns_server->instance = action->data.instance;
|
||||||
_mdns_restart_all_pcbs_no_instance();
|
_mdns_restart_all_pcbs_no_instance();
|
||||||
|
|
||||||
break;
|
|
||||||
case ACTION_SERVICES_CLEAR:
|
|
||||||
_mdns_send_final_bye(false);
|
|
||||||
a = _mdns_server->services;
|
|
||||||
_mdns_server->services = NULL;
|
|
||||||
while (a) {
|
|
||||||
mdns_srv_item_t *s = a;
|
|
||||||
a = a->next;
|
|
||||||
_mdns_remove_scheduled_service_packets(s->service);
|
|
||||||
_mdns_free_service(s->service);
|
|
||||||
free(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ACTION_SEARCH_ADD:
|
case ACTION_SEARCH_ADD:
|
||||||
_mdns_search_add(action->data.search_add.search);
|
_mdns_search_add(action->data.search_add.search);
|
||||||
@ -6453,27 +6438,27 @@ esp_err_t mdns_service_remove(const char *service_type, const char *proto)
|
|||||||
|
|
||||||
esp_err_t mdns_service_remove_all(void)
|
esp_err_t mdns_service_remove_all(void)
|
||||||
{
|
{
|
||||||
if (!_mdns_server) {
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
MDNS_SERVICE_LOCK();
|
MDNS_SERVICE_LOCK();
|
||||||
|
esp_err_t ret = ESP_OK;
|
||||||
|
ESP_GOTO_ON_FALSE(_mdns_server, ESP_ERR_INVALID_ARG, done, TAG, "Invalid state");
|
||||||
if (!_mdns_server->services) {
|
if (!_mdns_server->services) {
|
||||||
MDNS_SERVICE_UNLOCK();
|
goto done;
|
||||||
return ESP_OK;
|
|
||||||
}
|
}
|
||||||
MDNS_SERVICE_UNLOCK();
|
|
||||||
|
|
||||||
mdns_action_t *action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
|
_mdns_send_final_bye(false);
|
||||||
if (!action) {
|
mdns_srv_item_t *services = _mdns_server->services;
|
||||||
HOOK_MALLOC_FAILED;
|
_mdns_server->services = NULL;
|
||||||
return ESP_ERR_NO_MEM;
|
while (services) {
|
||||||
|
mdns_srv_item_t *s = services;
|
||||||
|
services = services->next;
|
||||||
|
_mdns_remove_scheduled_service_packets(s->service);
|
||||||
|
_mdns_free_service(s->service);
|
||||||
|
free(s);
|
||||||
}
|
}
|
||||||
action->type = ACTION_SERVICES_CLEAR;
|
|
||||||
if (xQueueSend(_mdns_server->action_queue, &action, (TickType_t)0) != pdPASS) {
|
done:
|
||||||
free(action);
|
MDNS_SERVICE_UNLOCK();
|
||||||
return ESP_ERR_NO_MEM;
|
return ret;
|
||||||
}
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -187,7 +187,6 @@ typedef enum {
|
|||||||
ACTION_SYSTEM_EVENT,
|
ACTION_SYSTEM_EVENT,
|
||||||
ACTION_HOSTNAME_SET,
|
ACTION_HOSTNAME_SET,
|
||||||
ACTION_INSTANCE_SET,
|
ACTION_INSTANCE_SET,
|
||||||
ACTION_SERVICES_CLEAR,
|
|
||||||
ACTION_SEARCH_ADD,
|
ACTION_SEARCH_ADD,
|
||||||
ACTION_SEARCH_SEND,
|
ACTION_SEARCH_SEND,
|
||||||
ACTION_SEARCH_END,
|
ACTION_SEARCH_END,
|
||||||
|
Reference in New Issue
Block a user