Skip to content

Commit

Permalink
Fix leak when allocating standard file handles
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Jan 9, 2025
1 parent 5f904d0 commit 041edc1
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions Source/GSFileHandle.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,23 @@ - (void) receivedEventWrite;

@implementation GSFileHandle

+ (void) atExit
{
DESTROY(fh_stdin);
DESTROY(fh_stdout);
DESTROY(fh_stderr);
}

+ (void) initialize
{
[GSTcpTune class];
static BOOL beenHere = NO;

if (NO == beenHere)
{
beenHere = YES;
[GSTcpTune class];
[self registerAtExit];
}
}

/**
Expand Down Expand Up @@ -189,6 +203,8 @@ + (id) allocWithZone: (NSZone*)z

- (void) dealloc
{
NSString *err = nil;

[self ignoreReadDescriptor];
[self ignoreWriteDescriptor];

Expand All @@ -213,23 +229,17 @@ - (void) dealloc
if (self == fh_stdin)
{
fh_stdin = nil;
DEALLOC
[NSException raise: NSGenericException
format: @"Attempt to deallocate standard input handle"];
err = @"standard input";
}
if (self == fh_stdout)
{
fh_stdout = nil;
DEALLOC
[NSException raise: NSGenericException
format: @"Attempt to deallocate standard output handle"];
err = @"standard output";
}
if (self == fh_stderr)
{
fh_stderr = nil;
DEALLOC
[NSException raise: NSGenericException
format: @"Attempt to deallocate standard error handle"];
err = @"standard error";
}
DESTROY(address);
DESTROY(service);
Expand All @@ -240,7 +250,12 @@ - (void) dealloc
* containing the deallocated object. Thanks to David for this fix.
*/
[self finalize];
[super dealloc];
DEALLOC
if (err)
{
[NSException raise: NSGenericException
format: @"Deallocation of %@ handle", err];
}
}

- (void) finalize
Expand Down

0 comments on commit 041edc1

Please sign in to comment.