Skip to content

Commit d8c3fe2

Browse files
author
karnevil9
committed
Fixed analyzer warning in AsyncUdpSocket.m
Fixed analyzer's 'possible leak' warning in -[AsyncUdpSocket doReceive:] by using an NSData local variable instead of theCurrentReceive->buffer to do the test of whether'buf' needs to be freed.
1 parent 52b6e3c commit d8c3fe2

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
@@ -2076,6 +2076,7 @@ - (void)doReceive:(CFSocketRef)theSocket
20762076

20772077
if([self hasBytesAvailable:theSocket])
20782078
{
2079+
NSData* bufferData = nil;
20792080
ssize_t result;
20802081
CFSocketNativeHandle theNativeSocket = CFSocketGetNative(theSocket);
20812082

@@ -2109,9 +2110,10 @@ - (void)doReceive:(CFSocketRef)theSocket
21092110
{
21102111
buf = realloc(buf, result);
21112112
}
2112-
theCurrentReceive->buffer = [[NSData alloc] initWithBytesNoCopy:buf
2113+
bufferData = [[NSData alloc] initWithBytesNoCopy:buf
21132114
length:result
21142115
freeWhenDone:YES];
2116+
theCurrentReceive->buffer = bufferData;
21152117
theCurrentReceive->host = host;
21162118
theCurrentReceive->port = port;
21172119
}
@@ -2143,9 +2145,10 @@ - (void)doReceive:(CFSocketRef)theSocket
21432145
{
21442146
buf = realloc(buf, result);
21452147
}
2146-
theCurrentReceive->buffer = [[NSData alloc] initWithBytesNoCopy:buf
2148+
bufferData = [[NSData alloc] initWithBytesNoCopy:buf
21472149
length:result
21482150
freeWhenDone:YES];
2151+
theCurrentReceive->buffer = bufferData;
21492152
theCurrentReceive->host = host;
21502153
theCurrentReceive->port = port;
21512154
}
@@ -2155,8 +2158,8 @@ - (void)doReceive:(CFSocketRef)theSocket
21552158
}
21562159

21572160
// Check to see if we need to free our alloc'd buffer
2158-
// If the buffer is non-nil, this means it has taken ownership of the buffer
2159-
if(theCurrentReceive->buffer == nil)
2161+
// If bufferData is non-nil, it has taken ownership of the buffer
2162+
if(bufferData == nil)
21602163
{
21612164
free(buf);
21622165
}

0 commit comments

Comments
 (0)