Skip to content

Commit

Permalink
Fix memory leak by freeing owned image bytes after reading barcode
Browse files Browse the repository at this point in the history
  • Loading branch information
khoren93 committed Jun 4, 2024
1 parent 0ba8b45 commit e187556
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/native_zxing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ CodeResult _readBarcode(const DecodeBarcodeParams& params) noexcept
ReaderOptions hints = createReaderOptions(params);
Result result = ReadBarcode(image, hints);

// Dart passes us an owned image bytes pointer; we need to free it after
delete[] params.bytes;

int duration = elapsed_ms(start);
platform_log("Read Barcode in: %d ms\n", duration);
return codeResultFromResult(result, duration, params.width, params.height);
Expand All @@ -227,6 +230,9 @@ CodeResults _readBarcodes(const DecodeBarcodeParams& params) noexcept
ReaderOptions hints = createReaderOptions(params);
Results results = ReadBarcodes(image, hints);

// Dart passes us an owned image bytes pointer; we need to free it after
delete[] params.bytes;

int duration = elapsed_ms(start);
platform_log("Read Barcode in: %d ms\n", duration);

Expand Down

0 comments on commit e187556

Please sign in to comment.