Skip to content

Commit 93bd881

Browse files
authored
Change malloc to calloc (#14289)
1 parent 4de32c7 commit 93bd881

File tree

12 files changed

+18
-17
lines changed

12 files changed

+18
-17
lines changed

Crashlytics/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22
- [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).
3+
- [fixed] Updated all memory allocation from `malloc()` to `calloc()` (#14209).
34

45
# 11.5.0
56
- [changed] Updated `upload-symbols` to version 3.19, removed all methods require CFRelease and switch to modern classes (#13420).

Crashlytics/Crashlytics/Components/FIRCLSBinaryImage.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ static void FIRCLSBinaryImageChanged(bool added,
409409
// fill imageDetails fields using slice & vmaddr_slide
410410
FIRCLSBinaryImageFillInImageDetails(&imageDetails);
411411

412-
FIRCLSImageChange* change = malloc(sizeof(FIRCLSImageChange));
412+
FIRCLSImageChange* change = calloc(1, sizeof(FIRCLSImageChange));
413413
if (!change) return;
414414
change->added = added;
415415
change->details = imageDetails;

Crashlytics/Crashlytics/Helpers/FIRCLSAllocate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void* FIRCLSAllocatorSafeAllocateFromRegion(FIRCLSAllocationRegion* region, size
175175
// this shouldn't happen unless we make a mistake with our size pre-computations
176176
if ((uintptr_t)originalCursor - (uintptr_t)region->start + size > region->size) {
177177
FIRCLSSDKLog("Unable to allocate sufficient memory, falling back to malloc\n");
178-
void* ptr = malloc(size);
178+
void* ptr = calloc(1, size);
179179
if (!ptr) {
180180
FIRCLSSDKLog("Unable to malloc in FIRCLSAllocatorSafeAllocateFromRegion\n");
181181
return NULL;
@@ -197,7 +197,7 @@ void* FIRCLSAllocatorSafeAllocate(FIRCLSAllocatorRef allocator,
197197
if (!allocator) {
198198
// fall back to malloc in this case
199199
FIRCLSSDKLog("Allocator invalid, falling back to malloc\n");
200-
void* ptr = malloc(size);
200+
void* ptr = calloc(1, size);
201201
if (!ptr) {
202202
FIRCLSSDKLog("Unable to malloc in FIRCLSAllocatorSafeAllocate\n");
203203
return NULL;
@@ -207,7 +207,7 @@ void* FIRCLSAllocatorSafeAllocate(FIRCLSAllocatorRef allocator,
207207

208208
if (allocator->protectionEnabled) {
209209
FIRCLSSDKLog("Allocator already protected, falling back to malloc\n");
210-
void* ptr = malloc(size);
210+
void* ptr = calloc(1, size);
211211
if (!ptr) {
212212
FIRCLSSDKLog("Unable to malloc in FIRCLSAllocatorSafeAllocate\n");
213213
return NULL;

Crashlytics/Crashlytics/Helpers/FIRCLSFile.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static bool FIRCLSFileInit(
7474

7575
file->bufferWrites = bufferWrites;
7676
if (bufferWrites) {
77-
file->writeBuffer = malloc(FIRCLSWriteBufferLength * sizeof(char));
77+
file->writeBuffer = calloc(1, FIRCLSWriteBufferLength * sizeof(char));
7878
if (!file->writeBuffer) {
7979
FIRCLSErrorLog(@"Unable to malloc in FIRCLSFileInit");
8080
return false;
@@ -668,7 +668,7 @@ void FIRCLSFileWriteArrayEntryHexEncodedString(FIRCLSFile* file, const char* val
668668

669669
NSString* FIRCLSFileHexEncodeString(const char* string) {
670670
size_t length = strlen(string);
671-
char* encodedBuffer = malloc(length * 2 + 1);
671+
char* encodedBuffer = calloc(1, length * 2 + 1);
672672

673673
if (!encodedBuffer) {
674674
FIRCLSErrorLog(@"Unable to malloc in FIRCLSFileHexEncodeString");
@@ -693,7 +693,7 @@ void FIRCLSFileWriteArrayEntryHexEncodedString(FIRCLSFile* file, const char* val
693693

694694
NSString* FIRCLSFileHexDecodeString(const char* string) {
695695
size_t length = strlen(string);
696-
char* decodedBuffer = malloc(length); // too long, but safe
696+
char* decodedBuffer = calloc(1, length); // too long, but safe
697697
if (!decodedBuffer) {
698698
FIRCLSErrorLog(@"Unable to malloc in FIRCLSFileHexDecodeString");
699699
return nil;

Crashlytics/Crashlytics/Helpers/FIRCLSUtility.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void FIRCLSRedactUUID(char* value) {
185185
// null terminator
186186
length = [data length];
187187
size = (length * 2) + 1;
188-
buffer = malloc(sizeof(char) * size);
188+
buffer = calloc(1, sizeof(char) * size);
189189

190190
if (!buffer) {
191191
FIRCLSErrorLog(@"Unable to malloc in FIRCLSNSDataToNSString");

Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ - (google_crashlytics_FilesPayload)protoFilesPayload {
171171

172172
NSArray<NSString *> *clsRecords = [self clsRecordFilePaths];
173173
google_crashlytics_FilesPayload_File *files =
174-
malloc(sizeof(google_crashlytics_FilesPayload_File) * clsRecords.count);
174+
calloc(1, sizeof(google_crashlytics_FilesPayload_File) * clsRecords.count);
175175

176176
if (files == NULL) {
177177
// files and files_count are initialized to NULL and 0 by default.
@@ -271,7 +271,7 @@ - (google_crashlytics_Platforms)protoPlatformFromString:(NSString *)str {
271271
// For bytes, it is just a strict memeory copy of the data in NSData.
272272
// The whole structure will be freed as a part of process for deallocing report in dealloc() of
273273
// this class
274-
pb_bytes_array_t *pbBytes = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(data.length));
274+
pb_bytes_array_t *pbBytes = calloc(1, PB_BYTES_ARRAY_T_ALLOCSIZE(data.length));
275275
if (pbBytes == NULL) {
276276
return NULL;
277277
}

Crashlytics/Shared/FIRCLSByteUtility.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void FIRCLSSafeHexToString(const uint8_t *value, size_t length, char *outputBuff
5858
// null terminator
5959
length = data.length;
6060
size = (length * 2) + 1;
61-
buffer = malloc(sizeof(char) * size);
61+
buffer = calloc(1, sizeof(char) * size);
6262

6363
if (!buffer) {
6464
return nil;

Crashlytics/Shared/FIRCLSMachO/FIRCLSMachOBinary.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static void FIRCLSSafeHexToString(const uint8_t* value, size_t length, char* out
144144
// null terminator
145145
length = [data length];
146146
size = (length * 2) + 1;
147-
buffer = malloc(sizeof(char) * size);
147+
buffer = calloc(1, sizeof(char) * size);
148148

149149
if (!buffer) {
150150
return nil;

Crashlytics/UnitTests/FIRCLSCompactUnwindTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ @implementation FIRCLSCompactUnwindTests
3333
- (void)setUp {
3434
[super setUp];
3535

36-
_firclsContext.readonly = malloc(sizeof(FIRCLSReadOnlyContext));
36+
_firclsContext.readonly = calloc(1, sizeof(FIRCLSReadOnlyContext));
3737
_firclsContext.readonly->logPath = "/tmp/test.log";
3838
}
3939

Crashlytics/UnitTests/FIRCLSDwarfTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ @implementation FIRCLSDwarfTests
3333
- (void)setUp {
3434
[super setUp];
3535

36-
_firclsContext.readonly = malloc(sizeof(FIRCLSReadOnlyContext));
36+
_firclsContext.readonly = calloc(1, sizeof(FIRCLSReadOnlyContext));
3737
_firclsContext.readonly->logPath = "/tmp/test.log";
3838
}
3939

0 commit comments

Comments
 (0)