> There's a handy NSData-Compression class in Dustin Mierau's NetSocket > 0.9 sample code available here: > > http://blackholemedia.com/code/ > > Here's a snippet from the header file. > > @interface NSData (Compression) > - (NSData*)compressedData; > - (NSData*)compressedDataWithLevel:(int)inLevel; > - (NSData*)uncompressedData; > @end > > @interface NSMutableData (Compression) > - (BOOL)compress; > - (BOOL)uncompress; > @end
This code (from above) appears to leak: - (NSData*)compressedDataWithLevel:(int)inLevel { Bytef* data = (Bytef*)[self bytes]; uLongf originalLength = [self length]; uLongf bufferLength = ( [self length] * 1.1 ) + 16; Bytef* buffer; int err; if( inLevel > NSDataCompressionBest ) inLevel = NSDataCompressionBest; if( inLevel < Z_DEFAULT_COMPRESSION ) inLevel = NSDataCompressionNone; buffer = (Bytef*)malloc( (uInt)bufferLength ); err = compress2( buffer, &bufferLength, (const Bytef*)data, [self length], inLevel ); if( err != Z_OK ) { free( buffer ); return nil; } bcopy( buffer, buffer + sizeof( uLongf ), bufferLength ); bcopy( (void*)&originalLength, buffer, sizeof( uLongf ) ); return [NSData dataWithBytesNoCopy:buffer length:bufferLength + sizeof( uLongf )]; } If the compression is successful, and I later release the (compressed) NSData, buffer is still around, right? Is there an update to this code? How could I add buffer to a pool of sorts to be released when the object is released as it is just malloc'd. Thanks, Trygve _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]