Skip to content

Commit

Permalink
Fix HttpUpgrader duplicate stream de-allocation (#2722)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 authored Mar 7, 2024
1 parent 8939766 commit d9d97bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
11 changes: 4 additions & 7 deletions Sming/Components/rboot/src/Network/RbootHttpUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
11 changes: 4 additions & 7 deletions Sming/Libraries/OtaNetwork/src/HttpUpgrader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit d9d97bd

Please sign in to comment.