Fix memory leak in JPEG EXIF rotation (rotate90/rotate270)#2574
Open
iurisilvio wants to merge 1 commit into
Open
Fix memory leak in JPEG EXIF rotation (rotate90/rotate270)#2574iurisilvio wants to merge 1 commit into
iurisilvio wants to merge 1 commit into
Conversation
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 Automattic#2572
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2572.
The
rotate90androtate270lambdas inImage::rotatePixelsallocate a temporaryunrotatedbuffer vianew 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 * 4bytes) on eachloadImagecall.For a 1200×1800 test image (
recurser/exif-orientation-examplesLandscape_6.jpg, EXIFOrientation=6), 100 sequential loads leak 837 MiB (~8.4 MiB/iter, matchingwidth * height * 4 = 8,640,000bytes exactly). After this fix, RSS plateaus after the first ~10 iterations and stays flat.The full repro script and observed numbers are in #2572.
Diff is one line added to each lambda:
auto rotate90 = [](uint8_t* pixels, int width, int height, int channels) { ... + delete[] unrotated; }; auto rotate270 = [](uint8_t* pixels, int width, int height, int channels) { ... + delete[] unrotated; };