mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'contrib/github_pr_8103' into 'master'
mdns: Fix mDNS memory leak Closes IDFGH-6448 See merge request espressif/esp-idf!16701
This commit is contained in:
commit
9fc95216da
@ -2265,6 +2265,11 @@ static mdns_txt_linked_item_t * _mdns_allocate_txt(size_t num_items, mdns_txt_it
|
||||
}
|
||||
return new_txt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deallocate the txt linked list
|
||||
* @param txt pointer to the txt pointer to free, noop if txt==NULL
|
||||
*/
|
||||
static void _mdns_free_linked_txt(mdns_txt_linked_item_t *txt)
|
||||
{
|
||||
mdns_txt_linked_item_t *t;
|
||||
@ -2293,7 +2298,7 @@ static mdns_service_t * _mdns_create_service(const char * service, const char *
|
||||
uint16_t port, const char * instance, size_t num_items,
|
||||
mdns_txt_item_t txt[])
|
||||
{
|
||||
mdns_service_t * s = (mdns_service_t *)malloc(sizeof(mdns_service_t));
|
||||
mdns_service_t * s = (mdns_service_t *)calloc(1, sizeof(mdns_service_t));
|
||||
if (!s) {
|
||||
HOOK_MALLOC_FAILED;
|
||||
return NULL;
|
||||
@ -2301,8 +2306,7 @@ static mdns_service_t * _mdns_create_service(const char * service, const char *
|
||||
|
||||
mdns_txt_linked_item_t * new_txt = _mdns_allocate_txt(num_items, txt);
|
||||
if (num_items && new_txt == NULL) {
|
||||
free(s);
|
||||
return NULL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
s->priority = 0;
|
||||
@ -2315,8 +2319,7 @@ static mdns_service_t * _mdns_create_service(const char * service, const char *
|
||||
if (hostname) {
|
||||
s->hostname = strndup(hostname, MDNS_NAME_BUF_LEN - 1);
|
||||
if (!s->hostname) {
|
||||
free(s);
|
||||
return NULL;
|
||||
goto fail;
|
||||
}
|
||||
} else {
|
||||
s->hostname = NULL;
|
||||
@ -2324,18 +2327,24 @@ static mdns_service_t * _mdns_create_service(const char * service, const char *
|
||||
|
||||
s->service = strndup(service, MDNS_NAME_BUF_LEN - 1);
|
||||
if (!s->service) {
|
||||
free(s);
|
||||
return NULL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
s->proto = strndup(proto, MDNS_NAME_BUF_LEN - 1);
|
||||
if (!s->proto) {
|
||||
free((char *)s->service);
|
||||
free(s);
|
||||
return NULL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return s;
|
||||
|
||||
fail:
|
||||
_mdns_free_linked_txt(s->txt);
|
||||
free((char *)s->instance);
|
||||
free((char *)s->service);
|
||||
free((char *)s->proto);
|
||||
free((char *)s->hostname);
|
||||
free(s);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user