From 26be94e1b606c82a87c04770733343d1bd181dd0 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 11 May 2024 23:49:07 +0100 Subject: [PATCH] Fix: Memory leak in CoreTextFontCache. 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 7cb557fed3..f28e8091b0 100644 --- a/src/os/macosx/font_osx.cpp +++ b/src/os/macosx/font_osx.cpp @@ -254,8 +254,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);