From dce3db0fee31f06a2c2ecea2f3ef4a6fe2f1c371 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Wed, 28 Apr 2021 14:37:28 +0200 Subject: [PATCH] IOS-2794 This could work --- pantomime-lib/Framework/Pantomime/NSData+Extensions.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pantomime-lib/Framework/Pantomime/NSData+Extensions.m b/pantomime-lib/Framework/Pantomime/NSData+Extensions.m index 00faad7..6f100cf 100644 --- a/pantomime-lib/Framework/Pantomime/NSData+Extensions.m +++ b/pantomime-lib/Framework/Pantomime/NSData+Extensions.m @@ -441,7 +441,14 @@ static const char *hexDigit = "0123456789ABCDEF"; { const char *theBytes = [self bytes]; const char *newBytes = theBytes + range.location; - return [NSData dataWithBytesNoCopy:(void *) newBytes length:range.length]; + + // Let the NSData point to existing bytes without copy, + // and don't do anything to free them + return [[NSData alloc] initWithBytesNoCopy:(void *) newBytes + length:range.length + deallocator:^(void * _Nonnull bytes, NSUInteger length) { + // ignore, don't free anything + }]; } - (NSData *)dataByTrimmingWhiteSpaces