1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-19 08:15:49 +00:00

[mdns] Fix delete/malloc bug and store string constants in flash (#11105)

This commit is contained in:
J. Nick Koston
2025-10-07 18:19:29 -10:00
committed by GitHub
parent 0fe6e7169c
commit ec63247ae0
8 changed files with 61 additions and 51 deletions

View File

@@ -21,18 +21,18 @@ void MDNSComponent::setup() {
// part of the wire protocol to have an underscore, and for example ESP-IDF
// expects the underscore to be there, the ESP8266 implementation always adds
// the underscore itself.
auto *proto = service.proto.c_str();
while (*proto == '_') {
auto *proto = MDNS_STR_ARG(service.proto);
while (progmem_read_byte((const uint8_t *) proto) == '_') {
proto++;
}
auto *service_type = service.service_type.c_str();
while (*service_type == '_') {
auto *service_type = MDNS_STR_ARG(service.service_type);
while (progmem_read_byte((const uint8_t *) service_type) == '_') {
service_type++;
}
uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
MDNS.addService(service_type, proto, port);
MDNS.addService(FPSTR(service_type), FPSTR(proto), port);
for (const auto &record : service.txt_records) {
MDNS.addServiceTxt(service_type, proto, record.key.c_str(),
MDNS.addServiceTxt(FPSTR(service_type), FPSTR(proto), FPSTR(MDNS_STR_ARG(record.key)),
const_cast<TemplatableValue<std::string> &>(record.value).value().c_str());
}
}