Fixed a double release in a garbage collected environment.
authorDan Preston <danpreston@codechemistry.com>
Tue May 05 14:46:42 2009 -0700 (2009-05-05)
changeset 365165944a89b3
parent 35 a9dd5ac5ff11
child 37 7c7d5a0cb4d6
Fixed a double release in a garbage collected environment.
TCP/TCPConnection.m
     1.1 --- a/TCP/TCPConnection.m	Mon May 04 23:21:26 2009 -0700
     1.2 +++ b/TCP/TCPConnection.m	Tue May 05 14:46:42 2009 -0700
     1.3 @@ -75,10 +75,8 @@
     1.4      // +getStreamsToHost: is missing for some stupid reason on iPhone. Grrrrrrrrrr.
     1.5      CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)address.hostname, address.port,
     1.6                                         (CFReadStreamRef*)&input, (CFWriteStreamRef*)&output);
     1.7 -    if( input )
     1.8 -        [(id)CFMakeCollectable(input) autorelease];
     1.9 -    if( output )
    1.10 -        [(id)CFMakeCollectable(output) autorelease];
    1.11 +    if( input )  [NSMakeCollectable(input) autorelease];
    1.12 +    if( output ) [NSMakeCollectable(output) autorelease];
    1.13  #else
    1.14      [NSStream getStreamsToHost: [NSHost hostWithAddress: address.ipv4name]
    1.15                            port: address.port 
    1.16 @@ -120,17 +118,18 @@
    1.17      CFReadStreamRef readStream = NULL;
    1.18      CFWriteStreamRef writeStream = NULL;
    1.19      CFStreamCreatePairWithSocket(kCFAllocatorDefault, socket, &readStream, &writeStream);
    1.20 +	if( readStream )  [NSMakeCollectable(readStream) autorelease];
    1.21 +    if( writeStream ) [NSMakeCollectable(writeStream) autorelease];
    1.22 +	
    1.23      self = [self _initWithAddress: [IPAddress addressOfSocket: socket] 
    1.24 -                      inputStream: (NSInputStream*)CFMakeCollectable(readStream)
    1.25 -                     outputStream: (NSOutputStream*)CFMakeCollectable(writeStream)];
    1.26 +                      inputStream: (NSInputStream*)readStream
    1.27 +                     outputStream: (NSOutputStream*)writeStream];
    1.28      if( self ) {
    1.29          _isIncoming = YES;
    1.30          _server = [listener retain];
    1.31          CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
    1.32          CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
    1.33      }
    1.34 -    if(readStream) CFRelease(readStream);
    1.35 -    if(writeStream) CFRelease(writeStream);
    1.36      return self;
    1.37  }    
    1.38