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

zip file stream memory leak fix proposa,=l, switching to smart pointer. #998

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 3 additions & 5 deletions Sources/Core/ZipFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace spades {
SPADES_MARK_FUNCTION();
if (streaming) {
unzCloseCurrentFile(zip);
SPAssert(this == fs->currentStream);
SPAssert(this == fs->currentStream.get());
fs->currentStream = NULL;
}
}
Expand All @@ -79,7 +79,7 @@ namespace spades {
SPRaise("Zip file close error: 0x%08x", ret);
}

SPAssert(this == fs->currentStream);
SPAssert(this == fs->currentStream.get());
fs->currentStream = NULL;
}
}
Expand Down Expand Up @@ -343,7 +343,7 @@ namespace spades {

unzOpenCurrentFile(zip);
try {
currentStream = new ZipFileInputStream(this, zip);
currentStream.reset(new ZipFileInputStream(this, zip));
// load all data to allow seeking
auto stream = stmp::make_unique<DynamicMemoryStream>();
try {
Expand All @@ -354,10 +354,8 @@ namespace spades {
}
currentStream->ForceCloseUnzipFile();
stream->SetPosition(0);
delete currentStream;
return stream;
} catch (...) {
delete currentStream;
throw;
}
} catch (...) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/ZipFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace spades {

std::map<std::string, unz_file_pos_s> files;

ZipFileInputStream *currentStream;
std::unique_ptr<ZipFileInputStream> currentStream;

uint64_t cursorPos;

Expand Down