From 5ab12ad626ebdb9cd585e75bdb55141e97f183b9 Mon Sep 17 00:00:00 2001 From: Maor Barak Date: Mon, 20 Feb 2023 08:04:08 +0200 Subject: [PATCH] fix-ios-leaks - free rawBytes in UIImageExtension - free input in PyTorchMobilePlugin --- ios/Classes/Helpers/UIImageExtension.m | 1 + ios/Classes/PyTorchMobilePlugin.mm | 2 ++ 2 files changed, 3 insertions(+) diff --git a/ios/Classes/Helpers/UIImageExtension.m b/ios/Classes/Helpers/UIImageExtension.m index e9b58ae..416a88a 100644 --- a/ios/Classes/Helpers/UIImageExtension.m +++ b/ios/Classes/Helpers/UIImageExtension.m @@ -42,6 +42,7 @@ + (nullable float*)normalize:(UIImage*)image withMean:(NSArray*)mean normalizedBuffer[w * h * 2 + i] = (rawBytes[i * 4 + 2] / 255.0 - mean[2].floatValue) / std[2].floatValue; } + free(rawBytes); return normalizedBuffer; } diff --git a/ios/Classes/PyTorchMobilePlugin.mm b/ios/Classes/PyTorchMobilePlugin.mm index b9a714f..df36630 100644 --- a/ios/Classes/PyTorchMobilePlugin.mm +++ b/ios/Classes/PyTorchMobilePlugin.mm @@ -101,6 +101,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { } catch (const std::exception& e) { NSLog(@"PyTorchMobile: %s", e.what()); } + + free(input); break; }