Skip to content

Commit

Permalink
Merge pull request #594 from openzim/fix_compression_realloc
Browse files Browse the repository at this point in the history
[Compression] Correctly try to reallocate only when no output data.
  • Loading branch information
kelson42 committed Jul 31, 2021
2 parents 6b69bc0 + d915b18 commit 855dfe0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,19 @@ class Compressor
}
case CompStatus::STREAM_END:
return RunnerStatus::NEED_MORE;
case CompStatus::BUF_ERROR: {
//Not enought output size
ret_size *= 2;
std::unique_ptr<char[]> new_ret_data(new char[ret_size]);
memcpy(new_ret_data.get(), ret_data.get(), stream.total_out);
stream.next_out = (unsigned char*)(new_ret_data.get() + stream.total_out);
stream.avail_out = ret_size - stream.total_out;
ret_data = std::move(new_ret_data);
continue;
}
case CompStatus::BUF_ERROR:
if (stream.avail_out == 0) {
//Not enought output size
ret_size *= 2;
std::unique_ptr<char[]> new_ret_data(new char[ret_size]);
memcpy(new_ret_data.get(), ret_data.get(), stream.total_out);
stream.next_out = (unsigned char*)(new_ret_data.get() + stream.total_out);
stream.avail_out = ret_size - stream.total_out;
ret_data = std::move(new_ret_data);
continue;
} else {
return RunnerStatus::ERROR;
}
break;
default:
// unreachable
Expand Down

0 comments on commit 855dfe0

Please sign in to comment.