diff --git a/Crashlytics/CHANGELOG.md b/Crashlytics/CHANGELOG.md index 59058cf574c..598aed30656 100644 --- a/Crashlytics/CHANGELOG.md +++ b/Crashlytics/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased - [fixed] Updated `upload-symbols` to version 3.20, wait for `debug.dylib` DWARF content getting generated when build with `--build-phase` option. Added `debug.dylib` DWARF content to run script input file list for user who enabled user script sandboxing (#14054). +- [fixed] Updated all memory allocation from `malloc()` to `calloc()` (#14209). # 11.5.0 - [changed] Updated `upload-symbols` to version 3.19, removed all methods require CFRelease and switch to modern classes (#13420). diff --git a/Crashlytics/Crashlytics/Components/FIRCLSBinaryImage.m b/Crashlytics/Crashlytics/Components/FIRCLSBinaryImage.m index 35cb32b02fb..c7e1a602e83 100644 --- a/Crashlytics/Crashlytics/Components/FIRCLSBinaryImage.m +++ b/Crashlytics/Crashlytics/Components/FIRCLSBinaryImage.m @@ -409,7 +409,7 @@ static void FIRCLSBinaryImageChanged(bool added, // fill imageDetails fields using slice & vmaddr_slide FIRCLSBinaryImageFillInImageDetails(&imageDetails); - FIRCLSImageChange* change = malloc(sizeof(FIRCLSImageChange)); + FIRCLSImageChange* change = calloc(1, sizeof(FIRCLSImageChange)); if (!change) return; change->added = added; change->details = imageDetails; diff --git a/Crashlytics/Crashlytics/Helpers/FIRCLSAllocate.c b/Crashlytics/Crashlytics/Helpers/FIRCLSAllocate.c index 206b9a4e80d..acf78d98496 100644 --- a/Crashlytics/Crashlytics/Helpers/FIRCLSAllocate.c +++ b/Crashlytics/Crashlytics/Helpers/FIRCLSAllocate.c @@ -175,7 +175,7 @@ void* FIRCLSAllocatorSafeAllocateFromRegion(FIRCLSAllocationRegion* region, size // this shouldn't happen unless we make a mistake with our size pre-computations if ((uintptr_t)originalCursor - (uintptr_t)region->start + size > region->size) { FIRCLSSDKLog("Unable to allocate sufficient memory, falling back to malloc\n"); - void* ptr = malloc(size); + void* ptr = calloc(1, size); if (!ptr) { FIRCLSSDKLog("Unable to malloc in FIRCLSAllocatorSafeAllocateFromRegion\n"); return NULL; @@ -197,7 +197,7 @@ void* FIRCLSAllocatorSafeAllocate(FIRCLSAllocatorRef allocator, if (!allocator) { // fall back to malloc in this case FIRCLSSDKLog("Allocator invalid, falling back to malloc\n"); - void* ptr = malloc(size); + void* ptr = calloc(1, size); if (!ptr) { FIRCLSSDKLog("Unable to malloc in FIRCLSAllocatorSafeAllocate\n"); return NULL; @@ -207,7 +207,7 @@ void* FIRCLSAllocatorSafeAllocate(FIRCLSAllocatorRef allocator, if (allocator->protectionEnabled) { FIRCLSSDKLog("Allocator already protected, falling back to malloc\n"); - void* ptr = malloc(size); + void* ptr = calloc(1, size); if (!ptr) { FIRCLSSDKLog("Unable to malloc in FIRCLSAllocatorSafeAllocate\n"); return NULL; diff --git a/Crashlytics/Crashlytics/Helpers/FIRCLSFile.m b/Crashlytics/Crashlytics/Helpers/FIRCLSFile.m index 204782a633b..1f4d2a0c836 100644 --- a/Crashlytics/Crashlytics/Helpers/FIRCLSFile.m +++ b/Crashlytics/Crashlytics/Helpers/FIRCLSFile.m @@ -74,7 +74,7 @@ static bool FIRCLSFileInit( file->bufferWrites = bufferWrites; if (bufferWrites) { - file->writeBuffer = malloc(FIRCLSWriteBufferLength * sizeof(char)); + file->writeBuffer = calloc(1, FIRCLSWriteBufferLength * sizeof(char)); if (!file->writeBuffer) { FIRCLSErrorLog(@"Unable to malloc in FIRCLSFileInit"); return false; @@ -668,7 +668,7 @@ void FIRCLSFileWriteArrayEntryHexEncodedString(FIRCLSFile* file, const char* val NSString* FIRCLSFileHexEncodeString(const char* string) { size_t length = strlen(string); - char* encodedBuffer = malloc(length * 2 + 1); + char* encodedBuffer = calloc(1, length * 2 + 1); if (!encodedBuffer) { FIRCLSErrorLog(@"Unable to malloc in FIRCLSFileHexEncodeString"); @@ -693,7 +693,7 @@ void FIRCLSFileWriteArrayEntryHexEncodedString(FIRCLSFile* file, const char* val NSString* FIRCLSFileHexDecodeString(const char* string) { size_t length = strlen(string); - char* decodedBuffer = malloc(length); // too long, but safe + char* decodedBuffer = calloc(1, length); // too long, but safe if (!decodedBuffer) { FIRCLSErrorLog(@"Unable to malloc in FIRCLSFileHexDecodeString"); return nil; diff --git a/Crashlytics/Crashlytics/Helpers/FIRCLSUtility.m b/Crashlytics/Crashlytics/Helpers/FIRCLSUtility.m index 7592aa01424..21e87ac66fd 100644 --- a/Crashlytics/Crashlytics/Helpers/FIRCLSUtility.m +++ b/Crashlytics/Crashlytics/Helpers/FIRCLSUtility.m @@ -185,7 +185,7 @@ void FIRCLSRedactUUID(char* value) { // null terminator length = [data length]; size = (length * 2) + 1; - buffer = malloc(sizeof(char) * size); + buffer = calloc(1, sizeof(char) * size); if (!buffer) { FIRCLSErrorLog(@"Unable to malloc in FIRCLSNSDataToNSString"); diff --git a/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m b/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m index 900f93c20ee..543c6bfc718 100644 --- a/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m +++ b/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m @@ -171,7 +171,7 @@ - (google_crashlytics_FilesPayload)protoFilesPayload { NSArray *clsRecords = [self clsRecordFilePaths]; google_crashlytics_FilesPayload_File *files = - malloc(sizeof(google_crashlytics_FilesPayload_File) * clsRecords.count); + calloc(1, sizeof(google_crashlytics_FilesPayload_File) * clsRecords.count); if (files == NULL) { // files and files_count are initialized to NULL and 0 by default. @@ -271,7 +271,7 @@ - (google_crashlytics_Platforms)protoPlatformFromString:(NSString *)str { // For bytes, it is just a strict memeory copy of the data in NSData. // The whole structure will be freed as a part of process for deallocing report in dealloc() of // this class - pb_bytes_array_t *pbBytes = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(data.length)); + pb_bytes_array_t *pbBytes = calloc(1, PB_BYTES_ARRAY_T_ALLOCSIZE(data.length)); if (pbBytes == NULL) { return NULL; } diff --git a/Crashlytics/Shared/FIRCLSByteUtility.m b/Crashlytics/Shared/FIRCLSByteUtility.m index 8298bf1299c..f27d60be7a3 100644 --- a/Crashlytics/Shared/FIRCLSByteUtility.m +++ b/Crashlytics/Shared/FIRCLSByteUtility.m @@ -58,7 +58,7 @@ void FIRCLSSafeHexToString(const uint8_t *value, size_t length, char *outputBuff // null terminator length = data.length; size = (length * 2) + 1; - buffer = malloc(sizeof(char) * size); + buffer = calloc(1, sizeof(char) * size); if (!buffer) { return nil; diff --git a/Crashlytics/Shared/FIRCLSMachO/FIRCLSMachOBinary.m b/Crashlytics/Shared/FIRCLSMachO/FIRCLSMachOBinary.m index 02e9125af74..2b8b67915a3 100644 --- a/Crashlytics/Shared/FIRCLSMachO/FIRCLSMachOBinary.m +++ b/Crashlytics/Shared/FIRCLSMachO/FIRCLSMachOBinary.m @@ -144,7 +144,7 @@ static void FIRCLSSafeHexToString(const uint8_t* value, size_t length, char* out // null terminator length = [data length]; size = (length * 2) + 1; - buffer = malloc(sizeof(char) * size); + buffer = calloc(1, sizeof(char) * size); if (!buffer) { return nil; diff --git a/Crashlytics/UnitTests/FIRCLSCompactUnwindTests.m b/Crashlytics/UnitTests/FIRCLSCompactUnwindTests.m index 204911949b2..fc5bcabf73a 100644 --- a/Crashlytics/UnitTests/FIRCLSCompactUnwindTests.m +++ b/Crashlytics/UnitTests/FIRCLSCompactUnwindTests.m @@ -33,7 +33,7 @@ @implementation FIRCLSCompactUnwindTests - (void)setUp { [super setUp]; - _firclsContext.readonly = malloc(sizeof(FIRCLSReadOnlyContext)); + _firclsContext.readonly = calloc(1, sizeof(FIRCLSReadOnlyContext)); _firclsContext.readonly->logPath = "/tmp/test.log"; } diff --git a/Crashlytics/UnitTests/FIRCLSDwarfTests.m b/Crashlytics/UnitTests/FIRCLSDwarfTests.m index 4dfb98d1c2d..7a97afa1abb 100644 --- a/Crashlytics/UnitTests/FIRCLSDwarfTests.m +++ b/Crashlytics/UnitTests/FIRCLSDwarfTests.m @@ -33,7 +33,7 @@ @implementation FIRCLSDwarfTests - (void)setUp { [super setUp]; - _firclsContext.readonly = malloc(sizeof(FIRCLSReadOnlyContext)); + _firclsContext.readonly = calloc(1, sizeof(FIRCLSReadOnlyContext)); _firclsContext.readonly->logPath = "/tmp/test.log"; } diff --git a/Crashlytics/UnitTests/FIRCLSFileTests.m b/Crashlytics/UnitTests/FIRCLSFileTests.m index b8895f68a67..09e3ba2428c 100644 --- a/Crashlytics/UnitTests/FIRCLSFileTests.m +++ b/Crashlytics/UnitTests/FIRCLSFileTests.m @@ -217,7 +217,7 @@ - (void)hexEncodingLongStringWithFile:(FIRCLSFile *)file filePath:(NSString *)filePath length:(size_t)length buffered:(BOOL)buffered { - char *longString = malloc(length * sizeof(char)); + char *longString = calloc(1, length * sizeof(char)); memset(longString, 'a', length); // fill it with 'a' characters longString[length - 1] = 0; // null terminate @@ -432,7 +432,7 @@ - (void)closeAndOpenAlternatingBufferedOptionWithFile:(FIRCLSFile *)file - (void)testLoggingInputLongerThanBuffer { size_t inputLength = (FIRCLSWriteBufferLength + 2) * sizeof(char); - char *input = malloc(inputLength); + char *input = calloc(1, inputLength); for (size_t i = 0; i < inputLength - 1; i++) { input[i] = i % 26 + 'a'; } diff --git a/Crashlytics/UnitTests/FIRCLSLoggingTests.m b/Crashlytics/UnitTests/FIRCLSLoggingTests.m index b79341fe06e..475d8c79bdb 100644 --- a/Crashlytics/UnitTests/FIRCLSLoggingTests.m +++ b/Crashlytics/UnitTests/FIRCLSLoggingTests.m @@ -302,7 +302,7 @@ - (void)testUserLogNil { - (void)testLargeLogLine { size_t strLength = 100 * 1024; // Attempt to write 100k of data - char* longLine = malloc(strLength + 1); + char* longLine = calloc(1, strLength + 1); memset(longLine, 'a', strLength); longLine[strLength] = '\0'; NSString* longStr = [[NSString alloc] initWithBytesNoCopy:longLine