fix(mdns): Fix mdns mdns_lookup_service() to handle empty TXT

the lookup_service API calls _copy_mdns_txt_items(), which tries to
allocate new TXT records, but didn't handle the case with no TXT.
Originally the _copy_mdns_txt_items() called calloc() with zero's which
returned NULL (on espressif toolchain), so it's safe, but we could see
an error message:
E (1170) mdns: Cannot allocate memory (line: 6191, free heap: 281368 bytes)
This commit addresses the empty TXT case and gets rid of the error
message.
This commit is contained in:
David Cermak
2024-08-19 11:28:50 +02:00
parent 0660ece128
commit d4da9cb079

View File

@ -6185,6 +6185,10 @@ static mdns_txt_item_t *_copy_mdns_txt_items(mdns_txt_linked_item_t *items, uint
ret_index++;
}
*txt_count = ret_index;
if (ret_index == 0) { // handle empty TXT
*txt_value_len = NULL;
return NULL;
}
ret = (mdns_txt_item_t *)calloc(ret_index, sizeof(mdns_txt_item_t));
*txt_value_len = (uint8_t *)calloc(ret_index, sizeof(uint8_t));
if (!ret || !(*txt_value_len)) {