Avoid leaks during encoding

This commit is contained in:
Surma
2020-08-03 19:36:11 +01:00
committed by Ingvar Stepanyan
parent cfba6e7bd5
commit 0218d0aac5
3 changed files with 15 additions and 14 deletions

View File

@@ -60,13 +60,14 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {
encoder->tileColsLog2 = options.tileColsLog2;
encoder->speed = options.speed;
avifResult encodeResult = avifEncoderWrite(encoder, image, &output);
if (encodeResult != AVIF_RESULT_OK) {
return val::null();
auto js_result = val::null();
if (encodeResult == AVIF_RESULT_OK) {
js_result = Uint8Array.new_(typed_memory_view(output.size, output.data));
}
auto js_result = Uint8Array.new_(typed_memory_view(output.size, output.data));
avifImageDestroy(image);
avifEncoderDestroy(encoder);
avifRWDataFree(&output);
return js_result;
}