From 43aa8e3c14eb367cd27bac7981dd3617243f0cf8 Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Sun, 17 May 2026 21:14:09 +0200 Subject: [PATCH] Fix memory leak in JPEG EXIF rotation (rotate90/rotate270) The rotate90 and rotate270 lambdas in Image::rotatePixels allocate a temporary 'unrotated' buffer via 'new uint8_t[n_bytes]' but never free it. Every JPEG decoded with EXIF orientation 5, 6, 7, or 8 leaks the full rotated pixel buffer (width * height * 4 bytes) on each loadImage call. For a 1200x1800 test image (recurser/exif-orientation-examples Landscape_6.jpg, EXIF Orientation=6), 100 sequential loads leak 837 MiB (~8.4 MiB/iter, matching width * height * 4 = 8,640,000 bytes exactly). After this fix, RSS plateaus after the first ~10 iterations. Fixes #2572 --- src/Image.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Image.cc b/src/Image.cc index 06dd564ae..d40e92145 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -1408,6 +1408,7 @@ Image::rotatePixels(uint8_t* pixels, int width, int height, int channels, std::memcpy(pixels + new_idx, unrotated + orig_idx, channels); } } + delete[] unrotated; }; auto rotate270 = [](uint8_t* pixels, int width, int height, int channels) { @@ -1424,6 +1425,7 @@ Image::rotatePixels(uint8_t* pixels, int width, int height, int channels, std::memcpy(pixels + new_idx, unrotated + orig_idx, channels); } } + delete[] unrotated; }; switch (orientation) {