Skip to content

Commit

Permalink
Free memory
Browse files Browse the repository at this point in the history
  • Loading branch information
edo9300 committed Jun 29, 2022
1 parent 97cc7c9 commit 5dd69bf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gframe/replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool Replay::OpenReplayFromBuffer(std::vector<uint8_t>&& contents) {
stream.avail_in = fake_header.size();
stream.next_in = fake_header.data();

stream.avail_out = pheader.datasize;
stream.avail_out = pheader.base.datasize;
stream.next_out = replay_data.data();

if(lzma_alone_decoder(&stream, UINT64_MAX) != LZMA_OK) {
Expand All @@ -153,12 +153,14 @@ bool Replay::OpenReplayFromBuffer(std::vector<uint8_t>&& contents) {
// this is should only feed the fake header, if for some reasons
// LZMA_STREAM_END is returned, then something went wrong
if(lzma_code(&stream, LZMA_RUN) != LZMA_OK) {
lzma_end(&stream);
Reset();
return false;
}
}

if(stream.total_out != 0) {
lzma_end(&stream);
Reset();
return false;
}
Expand All @@ -170,6 +172,7 @@ bool Replay::OpenReplayFromBuffer(std::vector<uint8_t>&& contents) {
auto ret = lzma_code(&stream, LZMA_RUN);
if(ret == LZMA_STREAM_END) {
if(stream.total_out != pheader.datasize) {
lzma_end(&stream);
Reset();
return false;
}
Expand All @@ -182,9 +185,11 @@ bool Replay::OpenReplayFromBuffer(std::vector<uint8_t>&& contents) {
if(ret == LZMA_DATA_ERROR && stream.total_out == pheader.datasize)
break;
Reset();
lzma_end(&stream);
return false;
}
}
lzma_end(&stream);
} else {
contents.erase(contents.begin(), contents.begin() + sizeof(pheader));
replay_data = std::move(contents);
Expand Down

0 comments on commit 5dd69bf

Please sign in to comment.