Skip to content

Commit 380b1a5

Browse files
committed
Merge pull request robbiehanson#191 from karnevil9/master
Fixed analyzer warning in AsyncUdpSocket.m
2 parents 00bfd44 + d8c3fe2 commit 380b1a5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

RunLoop/AsyncUdpSocket.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,7 @@ - (void)doReceive:(CFSocketRef)theSocket
20882088

20892089
if([self hasBytesAvailable:theSocket])
20902090
{
2091+
NSData* bufferData = nil;
20912092
ssize_t result;
20922093
CFSocketNativeHandle theNativeSocket = CFSocketGetNative(theSocket);
20932094

@@ -2121,9 +2122,10 @@ - (void)doReceive:(CFSocketRef)theSocket
21212122
{
21222123
buf = realloc(buf, result);
21232124
}
2124-
theCurrentReceive->buffer = [[NSData alloc] initWithBytesNoCopy:buf
2125+
bufferData = [[NSData alloc] initWithBytesNoCopy:buf
21252126
length:result
21262127
freeWhenDone:YES];
2128+
theCurrentReceive->buffer = bufferData;
21272129
theCurrentReceive->host = host;
21282130
theCurrentReceive->port = port;
21292131
}
@@ -2155,9 +2157,10 @@ - (void)doReceive:(CFSocketRef)theSocket
21552157
{
21562158
buf = realloc(buf, result);
21572159
}
2158-
theCurrentReceive->buffer = [[NSData alloc] initWithBytesNoCopy:buf
2160+
bufferData = [[NSData alloc] initWithBytesNoCopy:buf
21592161
length:result
21602162
freeWhenDone:YES];
2163+
theCurrentReceive->buffer = bufferData;
21612164
theCurrentReceive->host = host;
21622165
theCurrentReceive->port = port;
21632166
}
@@ -2167,8 +2170,8 @@ - (void)doReceive:(CFSocketRef)theSocket
21672170
}
21682171

21692172
// Check to see if we need to free our alloc'd buffer
2170-
// If the buffer is non-nil, this means it has taken ownership of the buffer
2171-
if(theCurrentReceive->buffer == nil)
2173+
// If bufferData is non-nil, it has taken ownership of the buffer
2174+
if(bufferData == nil)
21722175
{
21732176
free(buf);
21742177
}

0 commit comments

Comments
 (0)