Close RAM bundle as soon as we read the magic number

Summary: No need to keep it open; it just makes it harder to reason about error handling.

Reviewed By: majak

Differential Revision: D3518200

fbshipit-source-id: dc1af6eb0f75de7e9f73513ed1dd522048f76670
This commit is contained in:
Adam Ernst
2016-07-07 13:31:19 -07:00
committed by Facebook Github Bot 2
parent 5323b77fba
commit b3ac5f06d2

View File

@@ -56,8 +56,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
}
uint32_t magicNumber;
if (fread(&magicNumber, sizeof(magicNumber), 1, bundle) != 1) {
fclose(bundle);
size_t readResult = fread(&magicNumber, sizeof(magicNumber), 1, bundle);
fclose(bundle);
if (readResult != 1) {
onComplete(RCTErrorWithMessage(@"Error reading bundle"), source, 0);
return;
}
@@ -81,7 +82,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
sourceLength = source.length;
}
fclose(bundle);
onComplete(error, source, sourceLength);
});
return;