translators/wonderbrush: Fix PVS 2320

Fix memory leak when realloc() fails.

Change-Id: I9665b1e618e675e324eb75aec586a41181957ced
Reviewed-on: https://review.haiku-os.org/c/1015
Reviewed-by: Barrett17 <[email protected]>
This commit is contained in:
Murai Takashi
2019-02-07 11:43:07 +00:00
committed by Barrett17
parent 7db28d3803
commit 0ca56bdecd
@@ -36,11 +36,17 @@ compress_bitmap_zlib(const BBitmap* bitmap, void** buffer, unsigned* size)
srcLength,
3);
if (ret == Z_OK) {
//printf("zlib compressed %ld bytes bitmap into %d bytes (%f%%)\n", srcLength, *size, ((float)*size / (float)srcLength) * 100.0);
if ((unsigned)ceilf(srcLength * 1.01) + 12 != *size)
*buffer = realloc(*buffer, *size);
result = true;
} else {
// printf("zlib compressed %ld bytes bitmap into %d bytes (%f%%)\n",
// srcLength, *size, ((float)*size / (float)srcLength) * 100.0);
if ((unsigned)ceilf(srcLength * 1.01) + 12 != *size) {
void* tmpBuffer = realloc(*buffer, *size);
if (tmpBuffer) {
*buffer = tmpBuffer;
result = true;
}
}
}
if (ret != Z_OK || !result) {
// error compressing
free(*buffer);
*buffer = NULL;