Skip to content

Commit 4379c7e

Browse files
committed
fix(mdns): Address minor review comments
1 parent 6b5fb91 commit 4379c7e

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

components/mdns/mdns_browser.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ static mdns_browse_t *browse_init(const char *service, const char *proto, mdns_b
152152
browse->service = mdns_mem_strndup(service, MDNS_NAME_BUF_LEN - 1);
153153
if (!browse->service) {
154154
browse_item_free(browse);
155+
HOOK_MALLOC_FAILED;
155156
return NULL;
156157
}
157158
}

components/mdns/mdns_netif.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66

77
#include <string.h>
8+
#include "sdkconfig.h"
89
#include "esp_log.h"
9-
#include "esp_check.h"
1010
#include "esp_event.h"
1111
#include "mdns.h"
1212
#include "mdns_private.h"
@@ -66,7 +66,6 @@ static mdns_interfaces_t s_esp_netifs[MDNS_MAX_INTERFACES] = {
6666
#endif
6767
};
6868

69-
7069
/**
7170
* @brief Helper to get either ETH or STA if the other is provided
7271
* Used when two interfaces are on the same subnet
@@ -178,7 +177,6 @@ static esp_err_t post_custom_action(mdns_if_t mdns_if, mdns_event_actions_t even
178177
return ESP_OK;
179178
}
180179

181-
182180
/**
183181
* @brief Dispatch interface changes based on system events
184182
*/
@@ -284,7 +282,6 @@ static void handle_system_event_for_preset(void *arg, esp_event_base_t event_bas
284282
}
285283
#endif /* CONFIG_MDNS_PREDEF_NETIF_STA || CONFIG_MDNS_PREDEF_NETIF_AP || CONFIG_MDNS_PREDEF_NETIF_ETH */
286284

287-
288285
static inline void set_default_duplicated_interfaces(void)
289286
{
290287
mdns_if_t wifi_sta_if = MDNS_MAX_INTERFACES;
@@ -384,7 +381,6 @@ esp_err_t mdns_priv_netif_deinit(void)
384381
/*
385382
* Public Methods
386383
* */
387-
388384
esp_err_t mdns_netif_action(esp_netif_t *esp_netif, mdns_event_actions_t event_action)
389385
{
390386
return post_custom_action(get_if_from_netif(esp_netif), event_action);

components/mdns/mdns_send.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#include <string.h>
7+
#include "sdkconfig.h"
78
#include "mdns_private.h"
89
#include "mdns_send.h"
910
#include "mdns_utils.h"

components/mdns/mdns_service.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#include <string.h>
7+
#include "sdkconfig.h"
78
#include "mdns_private.h"
89
#include "freertos/FreeRTOS.h"
910
#include "freertos/task.h"
@@ -258,13 +259,15 @@ static esp_err_t create_task_with_caps(void)
258259
static StaticTask_t mdns_task_buffer;
259260

260261
s_stack_buffer = mdns_mem_task_malloc(MDNS_SERVICE_STACK_DEPTH);
261-
ESP_GOTO_ON_FALSE(s_stack_buffer != NULL, ESP_FAIL, err, TAG, "failed to allocate memory for the mDNS task's stack");
262+
ESP_GOTO_ON_FALSE(s_stack_buffer != NULL, ESP_FAIL, alloc_failed, TAG, "failed to allocate memory for the mDNS task's stack");
262263

263264
s_service_task_handle = xTaskCreateStaticPinnedToCore(service_task, "mdns", MDNS_SERVICE_STACK_DEPTH, NULL, MDNS_TASK_PRIORITY, s_stack_buffer, &mdns_task_buffer, MDNS_TASK_AFFINITY);
264265
ESP_GOTO_ON_FALSE(s_service_task_handle != NULL, ESP_FAIL, err, TAG, "failed to create task for the mDNS");
265266

266267
return ret;
267268

269+
alloc_failed:
270+
HOOK_MALLOC_FAILED;
268271
err:
269272
mdns_mem_task_free(s_stack_buffer);
270273
return ret;

components/mdns/mdns_utils.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#include <string.h>
7+
#include "sdkconfig.h"
78
#include "mdns_private.h"
89
#include "mdns_mem_caps.h"
910
#include "esp_log.h"
1011
#include "mdns_utils.h"
1112
#include "mdns_responder.h"
1213

14+
static const char *TAG = "mdns_utils";
1315
static const char *MDNS_DEFAULT_DOMAIN = "local";
1416
static const char *MDNS_SUB_STR = "_sub";
1517

@@ -119,7 +121,7 @@ bool mdns_utils_hostname_is_ours(const char *hostname)
119121
bool mdns_utils_service_match(const mdns_service_t *srv, const char *service, const char *proto,
120122
const char *hostname)
121123
{
122-
if (!service || !proto || !srv->hostname) {
124+
if (!service || !proto || !srv || !srv->hostname) {
123125
return false;
124126
}
125127
return !strcasecmp(srv->service, service) && !strcasecmp(srv->proto, proto) &&
@@ -164,7 +166,7 @@ bool mdns_utils_service_match_instance(const mdns_service_t *srv, const char *in
164166
if (!service || !proto) {
165167
return false;
166168
}
167-
// instance==NULL -> _mdns_instance_name_match() will check the default instance
169+
// instance==NULL -> mdns_utils_instance_name_match() will check the default instance
168170
// hostname==NULL -> matches if instance, service and proto matches
169171
return !strcasecmp(srv->service, service) && mdns_utils_instance_name_match(srv->instance, instance) &&
170172
!strcasecmp(srv->proto, proto) && (mdns_utils_str_null_or_empty(hostname) || !strcasecmp(srv->hostname, hostname));
@@ -216,6 +218,7 @@ mdns_ip_addr_t *mdns_utils_copy_address_list(const mdns_ip_addr_t *address_list)
216218
while (address_list != NULL) {
217219
mdns_ip_addr_t *addr = (mdns_ip_addr_t *)mdns_mem_malloc(sizeof(mdns_ip_addr_t));
218220
if (addr == NULL) {
221+
HOOK_MALLOC_FAILED;
219222
mdns_utils_free_address_list(head);
220223
return NULL;
221224
}

components/mdns/private_include/mdns_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
#define queueFree(type, queue) while (queue) { type * _q = queue; queue = queue->next; free(_q); }
141141

142142
#ifndef HOOK_MALLOC_FAILED
143-
#define HOOK_MALLOC_FAILED do { ESP_LOGE(TAG, "Cannot allocate memory (line: %d, free heap: %" PRIu32 " bytes)", __LINE__, esp_get_free_heap_size()); } while(0)
143+
#define HOOK_MALLOC_FAILED do { ESP_LOGE(TAG, "Cannot allocate memory (%s(%d), free heap: %" PRIu32 " bytes)", __func__, __LINE__, esp_get_free_heap_size()); } while(0)
144144
#endif
145145

146146
typedef size_t mdns_if_t;

0 commit comments

Comments
 (0)