Skip to content

Commit

Permalink
Avoid unnecessary copying in Config::getSafeConfigFile()
Browse files Browse the repository at this point in the history
  • Loading branch information
mkfrey committed Dec 21, 2019
1 parent 64ca0ba commit 60ca263
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Homie/Boot/BootNormal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ void BootNormal::_advertise() {
{
char* safeConfigFile = Interface::get().getConfig().getSafeConfigFile();
packetId = Interface::get().getMqttClient().publish(_prefixMqttTopic(PSTR("/$implementation/config")), 1, true, safeConfigFile);
free(safeConfigFile);
delete safeConfigFile;
if (packetId != 0) _advertisementProgress.globalStep = AdvertisementProgress::GlobalStep::PUB_IMPLEMENTATION_VERSION;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Homie/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ char* Config::getSafeConfigFile() const {
parsedJson["mqtt"].as<JsonObject>().remove("password");

size_t jsonBufferLength = measureJson(jsonDoc) + 1;
std::unique_ptr<char[]> jsonString(new char[jsonBufferLength]);
serializeJson(jsonDoc, jsonString.get(), jsonBufferLength);
return strdup(jsonString.get());
char* jsonString = new char[jsonBufferLength];
serializeJson(jsonDoc, jsonString, jsonBufferLength);
return jsonString;
}

void Config::erase() {
Expand Down

0 comments on commit 60ca263

Please sign in to comment.