Skip to content

Commit 4bb9ea7

Browse files
committed
memory retain issue fix
1 parent ee787ce commit 4bb9ea7

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

ios/ReactNativeBlobUtilFS.mm

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -679,31 +679,41 @@ + (void) hash:(NSString *)path
679679
return;
680680
}
681681

682-
while ((dataChunk = [fileHandle readDataUpToLength:chunkSize error:&error]) && dataChunk.length > 0) {
683-
if (error) {
684-
return reject(@"EREAD", [NSString stringWithFormat:@"Error reading file '%@'", path], error);
685-
break;
686-
}
687-
688-
switch(hashAlgorithm) {
689-
case HashAlgorithmMD5:
690-
CC_MD5_Update(&md5Context, [dataChunk bytes], CC_LONG([dataChunk length]));
691-
break;
692-
case HashAlgorithmSHA1:
693-
CC_SHA1_Update(&sha1Context, [dataChunk bytes], CC_LONG([dataChunk length]));
694-
break;
695-
case HashAlgorithmSHA224:
696-
CC_SHA224_Update(&sha256Context, [dataChunk bytes], CC_LONG([dataChunk length]));
697-
break;
698-
case HashAlgorithmSHA256:
699-
CC_SHA256_Update(&sha256Context, [dataChunk bytes], CC_LONG([dataChunk length]));
700-
break;
701-
case HashAlgorithmSHA384:
702-
CC_SHA384_Update(&sha512Context, [dataChunk bytes], CC_LONG([dataChunk length]));
682+
while (true) {
683+
@autoreleasepool {
684+
dataChunk = [fileHandle readDataUpToLength:chunkSize error:&error];
685+
686+
if (error) {
687+
return reject(@"EREAD", [NSString stringWithFormat:@"Error reading file '%@'", path], error);
703688
break;
704-
case HashAlgorithmSHA512:
705-
CC_SHA512_Update(&sha512Context, [dataChunk bytes], CC_LONG([dataChunk length]));
689+
}
690+
691+
if (dataChunk == nil || dataChunk.length == 0) {
706692
break;
693+
}
694+
695+
switch(hashAlgorithm) {
696+
case HashAlgorithmMD5:
697+
CC_MD5_Update(&md5Context, [dataChunk bytes], CC_LONG([dataChunk length]));
698+
break;
699+
case HashAlgorithmSHA1:
700+
CC_SHA1_Update(&sha1Context, [dataChunk bytes], CC_LONG([dataChunk length]));
701+
break;
702+
case HashAlgorithmSHA224:
703+
CC_SHA224_Update(&sha256Context, [dataChunk bytes], CC_LONG([dataChunk length]));
704+
break;
705+
case HashAlgorithmSHA256:
706+
CC_SHA256_Update(&sha256Context, [dataChunk bytes], CC_LONG([dataChunk length]));
707+
break;
708+
case HashAlgorithmSHA384:
709+
CC_SHA384_Update(&sha512Context, [dataChunk bytes], CC_LONG([dataChunk length]));
710+
break;
711+
case HashAlgorithmSHA512:
712+
CC_SHA512_Update(&sha512Context, [dataChunk bytes], CC_LONG([dataChunk length]));
713+
break;
714+
}
715+
716+
dataChunk = nil;
707717
}
708718
}
709719

0 commit comments

Comments
 (0)