diff --git a/Sming/Components/rboot/src/Network/RbootHttpUpdater.cpp b/Sming/Components/rboot/src/Network/RbootHttpUpdater.cpp index 883dd60dad..95bf2a843a 100644 --- a/Sming/Components/rboot/src/Network/RbootHttpUpdater.cpp +++ b/Sming/Components/rboot/src/Network/RbootHttpUpdater.cpp @@ -49,17 +49,19 @@ void RbootHttpUpdater::start() int RbootHttpUpdater::itemComplete(HttpConnection& client, bool success) { + auto& it = items[currentItem]; + if(!success) { + it.stream.release(); // Owned by HttpRequest updateFailed(); return -1; } - auto& it = items[currentItem]; debug_d("Finished: URL: %s, Offset: 0x%X, Length: %u", it.url.c_str(), it.stream->getStartAddress(), it.stream->available()); it.size = it.stream->available(); - it.stream = nullptr; // the actual deletion will happen outside of this class + it.stream.release(); // the actual deletion will happen outside of this class currentItem++; return 0; @@ -77,11 +79,6 @@ int RbootHttpUpdater::updateComplete(HttpConnection& client, bool success) debug_d(" - item: %u, addr: 0x%X, url: %s", i, items[i].targetOffset, items[i].url.c_str()); } - if(!success) { - updateFailed(); - return -1; - } - if(updateDelegate) { updateDelegate(*this, true); } diff --git a/Sming/Libraries/OtaNetwork/src/HttpUpgrader.cpp b/Sming/Libraries/OtaNetwork/src/HttpUpgrader.cpp index 90b893391f..a45be2c22f 100644 --- a/Sming/Libraries/OtaNetwork/src/HttpUpgrader.cpp +++ b/Sming/Libraries/OtaNetwork/src/HttpUpgrader.cpp @@ -49,17 +49,19 @@ void HttpUpgrader::start() int HttpUpgrader::itemComplete(HttpConnection& client, bool success) { + auto& it = items[currentItem]; + if(!success) { + it.stream.release(); // Owned by HttpRequest updateFailed(); return -1; } - auto& it = items[currentItem]; debug_d("Finished: URL: %s, Offset: 0x%X, Length: %u", it.url.c_str(), it.partition.address(), it.stream->available()); it.size = it.stream->available(); - it.stream = nullptr; // the actual deletion will happen outside of this class + it.stream.release(); // the actual deletion will happen outside of this class currentItem++; return 0; @@ -77,11 +79,6 @@ int HttpUpgrader::updateComplete(HttpConnection& client, bool success) debug_d(" - item: %u, addr: 0x%X, url: %s", i, items[i].partition.address(), items[i].url.c_str()); } - if(!success) { - updateFailed(); - return -1; - } - if(updateDelegate) { updateDelegate(*this, true); }