Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HttpUpgrader duplicate stream de-allocation #2722

Merged
merged 5 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading