Skip to content

Commit 736c22c

Browse files
committed
Fixing crash and memory leak in GCDAsyncUdpSocket.
1 parent 2680461 commit 736c22c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

GCD/GCDAsyncUdpSocket.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,7 +3997,7 @@ - (void)doReceive
39973997
socket4FDBytesAvailable -= result;
39983998

39993999
if (result != bufSize) {
4000-
realloc(buf, result);
4000+
buf = realloc(buf, result);
40014001
}
40024002

40034003
data = [NSData dataWithBytesNoCopy:buf length:result freeWhenDone:YES];
@@ -4006,6 +4006,7 @@ - (void)doReceive
40064006
else
40074007
{
40084008
LogVerbose(@"recvfrom(socket4FD) = %@", [self errnoError]);
4009+
free(buf);
40094010
}
40104011
}
40114012
else
@@ -4030,7 +4031,7 @@ - (void)doReceive
40304031
socket6FDBytesAvailable -= result;
40314032

40324033
if (result != bufSize) {
4033-
realloc(buf, result);
4034+
buf = realloc(buf, result);
40344035
}
40354036

40364037
data = [NSData dataWithBytesNoCopy:buf length:result freeWhenDone:YES];
@@ -4039,6 +4040,7 @@ - (void)doReceive
40394040
else
40404041
{
40414042
LogVerbose(@"recvfrom(socket6FD) = %@", [self errnoError]);
4043+
free(buf);
40424044
}
40434045
}
40444046

0 commit comments

Comments
 (0)