Skip to content

Commit

Permalink
fix(mdns): Fix mdns mdns_lookup_service() to handle empty TXT
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
david-cermak authored and euripedesrocha committed Aug 19, 2024
1 parent 09db3ce commit 14cba6e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components/mdns/mdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 14cba6e

Please sign in to comment.