From c8d39924a705621f63bef3328f85c314c3ed4658 Mon Sep 17 00:00:00 2001 From: YeungKC <11473691+YeungKC@users.noreply.github.com> Date: Sun, 18 Oct 2026 12:46:53 +0900 Subject: [PATCH] string_tokenizer: free the UTF-8 copy in tokenize tokenize() did not free the buffer from toNativeUtf8(), so each call leaked a copy of the input string. CFStringCreateWithCString copies the bytes, so free the buffer after the call. --- packages/string_tokenizer/lib/string_tokenizer.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/string_tokenizer/lib/string_tokenizer.dart b/packages/string_tokenizer/lib/string_tokenizer.dart index 76c3f937..ad97e9e7 100644 --- a/packages/string_tokenizer/lib/string_tokenizer.dart +++ b/packages/string_tokenizer/lib/string_tokenizer.dart @@ -51,11 +51,13 @@ List tokenize( range.ref.location = 0; range.ref.length = string.length; + final utf8 = string.toNativeUtf8(); final cfString = _bindings.CFStringCreateWithCString( nullptr, - string.toNativeUtf8().cast(), + utf8.cast(), binding.CFStringBuiltInEncodings.kCFStringEncodingUTF8.value, ); + malloc.free(utf8); int optionsInt = 0; for (final option in options) {