Skip to content

Commit 8e07bc7

Browse files
iurisilviochearon
authored andcommitted
Use delete[] to free new[]-allocated buffer in decodeJPEGIntoSurface
`Image::decodeJPEGIntoSurface` allocates a buffer with `new uint8_t[]` and freed it with `free()` on the OOM error path — undefined behavior in C++ (`new[]` and `free()` may use different allocators, and even when they share one they may have different bookkeeping for the array size header). Every other deallocation of `new uint8_t[]` buffers in Image.cc uses `delete[]` correctly; this is the only outlier. Caught by `g++ -Wmismatched-new-delete`. Fixes #2573
1 parent b915755 commit 8e07bc7

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎src/Image.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ Image::decodeJPEGIntoSurface(jpeg_decompress_struct *args, Orientation orientati
839839

840840
uint8_t *src = new uint8_t[naturalWidth * args->output_components];
841841
if (!src) {
842-
free(data);
842+
delete[] data;
843843
jpeg_abort_decompress(args);
844844
jpeg_destroy_decompress(args);
845845
this->errorInfo.set(NULL, "malloc", errno);

0 commit comments

Comments
 (0)