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