Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Fix a small memory leak #500

Merged
merged 1 commit into from
Dec 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Classes/BITChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ - (void)persistDataItemQueue:(char **)eventBuffer {

// Make sure string (which points to BITTelemetryEventBuffer) is not changed.
char *previousBuffer = NULL;
char *newEmptyString = NULL;
char *newEmptyString = strdup("");
do {
newEmptyString = strdup("");
previousBuffer = *eventBuffer;

// This swaps pointers and makes sure eventBuffer now has the balue of newEmptyString.
Expand Down Expand Up @@ -417,13 +416,14 @@ void bit_appendStringToEventBuffer(NSString *string, char **eventBuffer) {
}

void bit_resetEventBuffer(char **eventBuffer) {
if (!eventBuffer) { return; }
if (!eventBuffer) {
return;
}

char *newEmptyString = NULL;
char *prevString = NULL;
char *newEmptyString = strdup("");
do {
prevString = *eventBuffer;
newEmptyString = strdup("");

// Compare pointers to strings to make sure we are still threadsafe!
if (OSAtomicCompareAndSwapPtr(prevString, newEmptyString, (void*)eventBuffer)) {
Expand Down