Skip to content

Commit d4da9cb

Browse files
committed
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.
1 parent 0660ece commit d4da9cb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

components/mdns/mdns.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6185,6 +6185,10 @@ static mdns_txt_item_t *_copy_mdns_txt_items(mdns_txt_linked_item_t *items, uint
61856185
ret_index++;
61866186
}
61876187
*txt_count = ret_index;
6188+
if (ret_index == 0) { // handle empty TXT
6189+
*txt_value_len = NULL;
6190+
return NULL;
6191+
}
61886192
ret = (mdns_txt_item_t *)calloc(ret_index, sizeof(mdns_txt_item_t));
61896193
*txt_value_len = (uint8_t *)calloc(ret_index, sizeof(uint8_t));
61906194
if (!ret || !(*txt_value_len)) {

0 commit comments

Comments
 (0)