Skip to content
This repository was archived by the owner on Jul 27, 2022. It is now read-only.

Commit 36f9f04

Browse files
committed
Fix memory leak when sinks throw an exception
This allows custom sink implementations which can throw an exception (for example, when there is insufficient space to store the output) to be used, while avoiding memory leaks which could occur in the event such an exception is thrown.
1 parent 65b9721 commit 36f9f04

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

gipfeli-internal.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,13 @@ size_t Gipfeli::CompressStream(
268268
}
269269

270270
if (scratch_output == dest) {
271-
writer->AppendMemBlock(new NewedMemBlock(scratch_output, output_size));
271+
NewedMemBlock* new_block = new NewedMemBlock(scratch_output, output_size);
272+
try {
273+
writer->AppendMemBlock(new_block);
274+
} catch (...) {
275+
delete new_block;
276+
throw;
277+
}
272278
scratch_output = NULL;
273279
scratch_output_size = 0;
274280
} else {

0 commit comments

Comments
 (0)