mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
mdns: resolve memory leak when txt record received multiple times
This commit is contained in:
parent
1f35716ef4
commit
c320a3ee4c
@ -2769,10 +2769,6 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
|
||||
if (search_result) {
|
||||
mdns_txt_item_t * txt = NULL;
|
||||
size_t txt_count = 0;
|
||||
_mdns_result_txt_create(data_ptr, data_len, &txt, &txt_count);
|
||||
if (!txt_count) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mdns_result_t * result = NULL;
|
||||
if (search_result->type == MDNS_TYPE_PTR) {
|
||||
@ -2792,9 +2788,12 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
|
||||
}
|
||||
}
|
||||
if (!result->txt) {
|
||||
_mdns_result_txt_create(data_ptr, data_len, &txt, &txt_count);
|
||||
if (txt_count) {
|
||||
result->txt = txt;
|
||||
result->txt_count = txt_count;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_mdns_search_result_add_txt(search_result, txt, txt_count, packet->tcpip_if, packet->ip_protocol);
|
||||
}
|
||||
@ -3305,7 +3304,7 @@ static void _mdns_search_result_add_txt(mdns_search_once_t * search, mdns_txt_it
|
||||
while (r) {
|
||||
if (r->tcpip_if == tcpip_if && r->ip_protocol == ip_protocol) {
|
||||
if (r->txt) {
|
||||
return;
|
||||
goto free_txt;
|
||||
}
|
||||
r->txt = txt;
|
||||
r->txt_count = txt_count;
|
||||
@ -3316,12 +3315,7 @@ static void _mdns_search_result_add_txt(mdns_search_once_t * search, mdns_txt_it
|
||||
if (!search->max_results || search->num_results < search->max_results) {
|
||||
r = (mdns_result_t *)malloc(sizeof(mdns_result_t));
|
||||
if (!r) {
|
||||
for (i=0; i<txt_count; i++) {
|
||||
free((char *)(txt[i].key));
|
||||
free((char *)(txt[i].value));
|
||||
}
|
||||
free(txt);
|
||||
return;
|
||||
goto free_txt;
|
||||
}
|
||||
|
||||
memset(r, 0 , sizeof(mdns_result_t));
|
||||
@ -3333,6 +3327,14 @@ static void _mdns_search_result_add_txt(mdns_search_once_t * search, mdns_txt_it
|
||||
search->result = r;
|
||||
search->num_results++;
|
||||
}
|
||||
return;
|
||||
|
||||
free_txt:
|
||||
for (i=0; i<txt_count; i++) {
|
||||
free((char *)(txt[i].key));
|
||||
free((char *)(txt[i].value));
|
||||
}
|
||||
free(txt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user