From f87c6990b062bf0c7bb08a64d86b691547d06e07 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 23 May 2024 21:07:11 +0100 Subject: [PATCH] Fix: Memory leak in CoreTextFontCache. (#12662) Temporary buffer for rendering glyphs was not freed after use. Instead let CGBitmapContextCreate() handle the buffer. > data may be a pointer to pixels. If you pass NULL, the context will create its own buffer and free that buffer itself later. If you pass your own buffer, the context will not free it; it remains your buffer that you must free after you release the context, hopefully for the last time. --- src/os/macosx/font_osx.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp index 2bd290f4e6..8d7987119a 100644 --- a/src/os/macosx/font_osx.cpp +++ b/src/os/macosx/font_osx.cpp @@ -242,8 +242,8 @@ const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa) /* We only need the alpha channel, as we apply our own colour constants to the sprite. */ int pitch = Align(bb_width, 16); - uint8_t *bmp = CallocT(bb_height * pitch); - CFAutoRelease context(CGBitmapContextCreate(bmp, bb_width, bb_height, 8, pitch, nullptr, kCGImageAlphaOnly)); + CFAutoRelease context(CGBitmapContextCreate(nullptr, bb_width, bb_height, 8, pitch, nullptr, kCGImageAlphaOnly)); + const uint8_t *bmp = static_cast(CGBitmapContextGetData(context.get())); /* Set antialias according to requirements. */ CGContextSetAllowsAntialiasing(context.get(), use_aa); CGContextSetAllowsFontSubpixelPositioning(context.get(), use_aa);