Skip to content

Commit fbac0f6

Browse files
iurisilviochearon
authored andcommitted
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
1 parent 8e07bc7 commit fbac0f6

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎src/Image.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,7 @@ Image::rotatePixels(uint8_t* pixels, int width, int height, int channels,
14061406
std::memcpy(pixels + new_idx, unrotated + orig_idx, channels);
14071407
}
14081408
}
1409+
delete[] unrotated;
14091410
};
14101411

14111412
auto rotate270 = [](uint8_t* pixels, int width, int height, int channels) {
@@ -1422,6 +1423,7 @@ Image::rotatePixels(uint8_t* pixels, int width, int height, int channels,
14221423
std::memcpy(pixels + new_idx, unrotated + orig_idx, channels);
14231424
}
14241425
}
1426+
delete[] unrotated;
14251427
};
14261428

14271429
switch (orientation) {

0 commit comments

Comments
 (0)