Fix memory leaks
We need autoreleasepools around the Objective C allocations. Signed-off-by: Christopher Snowhill <kode54@gmail.com>main
parent
bf8391aa0d
commit
e766b69a22
24
scpipe.mm
24
scpipe.mm
|
@ -23,9 +23,11 @@ static NSFileHandle *pipe_out = nil;
|
|||
|
||||
void put_bytes( const void * out, uint32_t size )
|
||||
{
|
||||
NSError *error;
|
||||
NSData *data = [NSData dataWithBytes:out length:size];
|
||||
[pipe_out writeData:data error:&error];
|
||||
@autoreleasepool {
|
||||
NSError *error;
|
||||
NSData *data = [NSData dataWithBytes:out length:size];
|
||||
[pipe_out writeData:data error:&error];
|
||||
}
|
||||
}
|
||||
|
||||
void put_code( uint32_t code )
|
||||
|
@ -35,13 +37,17 @@ void put_code( uint32_t code )
|
|||
|
||||
void get_bytes( void * in, uint32_t size )
|
||||
{
|
||||
NSError *error = nil;
|
||||
NSData *data = [pipe_in readDataUpToLength:size error:&error];
|
||||
if(!data || error) {
|
||||
memset( in, 0, size );
|
||||
NSUInteger bytesDone;
|
||||
@autoreleasepool {
|
||||
NSError *error = nil;
|
||||
NSData *data = [pipe_in readDataUpToLength:size error:&error];
|
||||
if(!data || error) {
|
||||
memset( in, 0, size );
|
||||
return;
|
||||
}
|
||||
bytesDone = [data length];
|
||||
memcpy(in, [data bytes], bytesDone);
|
||||
}
|
||||
NSUInteger bytesDone = [data length];
|
||||
memcpy(in, [data bytes], bytesDone);
|
||||
if(bytesDone < size) {
|
||||
memset(((uint8_t *)in) + bytesDone, 0, size - bytesDone);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue