From 69b26c89ecedd143bbe3cb82005d7a0ca75c34bc Mon Sep 17 00:00:00 2001 From: Wu Zhong Date: Fri, 22 Oct 2021 04:14:33 +0800 Subject: [PATCH] [iOS] Fixes key press related memory leaks (flutter/engine#29127) --- .../ios/framework/Source/FlutterEmbedderKeyResponder.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEmbedderKeyResponder.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEmbedderKeyResponder.mm index 15e9904d88..82c430093e 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEmbedderKeyResponder.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEmbedderKeyResponder.mm @@ -158,7 +158,7 @@ static uint64_t GetLogicalKeyForEvent(FlutterUIPressProxy* press, uint64_t physi const char* characters = getEventCharacters(press.key.charactersIgnoringModifiers, press.key.keyCode); NSString* keyLabel = - characters == nullptr ? nil : [[NSString alloc] initWithUTF8String:characters]; + characters == nullptr ? nil : [[[NSString alloc] initWithUTF8String:characters] autorelease]; NSUInteger keyLabelLength = [keyLabel length]; // If this key is printable, generate the logical key from its Unicode // value. Control keys such as ESC, CTRL, and SHIFT are not printable. HOME, @@ -514,11 +514,11 @@ void HandleResponse(bool handled, void* user_data); FlutterKeyCallbackGuard* guardedCallback = nil; switch (press.phase) { case UIPressPhaseBegan: - guardedCallback = [[FlutterKeyCallbackGuard alloc] initWithCallback:callback]; + guardedCallback = [[[FlutterKeyCallbackGuard alloc] initWithCallback:callback] autorelease]; [self handlePressBegin:press callback:guardedCallback]; break; case UIPressPhaseEnded: - guardedCallback = [[FlutterKeyCallbackGuard alloc] initWithCallback:callback]; + guardedCallback = [[[FlutterKeyCallbackGuard alloc] initWithCallback:callback] autorelease]; [self handlePressEnd:press callback:guardedCallback]; break; case UIPressPhaseChanged: @@ -623,7 +623,7 @@ void HandleResponse(bool handled, void* user_data); _responseId += 1; uint64_t responseId = _responseId; FlutterKeyPendingResponse* pending = - [[FlutterKeyPendingResponse alloc] initWithHandler:self responseId:responseId]; + [[[FlutterKeyPendingResponse alloc] initWithHandler:self responseId:responseId] autorelease]; [callback pendTo:_pendingResponses withId:responseId]; _sendEvent(event, HandleResponse, pending); }