Fix memory leaks

We need autoreleasepools around the Objective C allocations.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
main
Christopher Snowhill 2022-10-28 00:14:07 -07:00
parent bf8391aa0d
commit e766b69a22
1 changed files with 15 additions and 9 deletions

View File

@ -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 )
{ {
NSError *error; @autoreleasepool {
NSData *data = [NSData dataWithBytes:out length:size]; NSError *error;
[pipe_out writeData:data error:&error]; NSData *data = [NSData dataWithBytes:out length:size];
[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 )
{ {
NSError *error = nil; NSUInteger bytesDone;
NSData *data = [pipe_in readDataUpToLength:size error:&error]; @autoreleasepool {
if(!data || error) { NSError *error = nil;
memset( in, 0, size ); 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) { if(bytesDone < size) {
memset(((uint8_t *)in) + bytesDone, 0, size - bytesDone); memset(((uint8_t *)in) + bytesDone, 0, size - bytesDone);
} }