From a725079d001dce0ddf1a923248cefc67d24b7c00 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Wed, 16 Oct 2013 13:08:38 +0000 Subject: [PATCH] Fix a bug whereby the singleton NSFileHandle instances (stdin, stdout, stderr) are autoreleased and become dangling pointers on exit. Reported on Stack Overflow: http://stackoverflow.com/questions/19389749/why-gnustep-nsrunloop-quits-immediately-with-arc git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37245 72102866-910b-0410-8b05-ffd578937521 --- Source/GSFileHandle.m | 6 +++--- Tests/base/NSFileHandle/singleton.m | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 Tests/base/NSFileHandle/singleton.m diff --git a/Source/GSFileHandle.m b/Source/GSFileHandle.m index 6de02101d..055fd6feb 100644 --- a/Source/GSFileHandle.m +++ b/Source/GSFileHandle.m @@ -964,7 +964,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; else { self = [self initWithFileDescriptor: 2 closeOnDealloc: NO]; - fh_stderr = self; + ASSIGN(fh_stderr, self); if (self) { readOK = NO; @@ -982,7 +982,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; else { self = [self initWithFileDescriptor: 0 closeOnDealloc: NO]; - fh_stdin = self; + ASSIGN(fh_stdin, self); if (self) { writeOK = NO; @@ -1000,7 +1000,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; else { self = [self initWithFileDescriptor: 1 closeOnDealloc: NO]; - fh_stdout = self; + ASSIGN(fh_stdout, self); if (self) { readOK = NO; diff --git a/Tests/base/NSFileHandle/singleton.m b/Tests/base/NSFileHandle/singleton.m new file mode 100644 index 000000000..059061379 --- /dev/null +++ b/Tests/base/NSFileHandle/singleton.m @@ -0,0 +1,16 @@ +#import + +id a,b,c; + +int main(void) +{ + NSAutoreleasePool *p = [NSAutoreleasePool new]; + NSZombieEnabled = YES; + a = [NSFileHandle fileHandleWithStandardInput]; + b = [NSFileHandle fileHandleWithStandardOutput]; + c = [NSFileHandle fileHandleWithStandardError]; + [p drain]; + assert(0 != [a description]); + assert(0 != [b description]); + assert(0 != [c description]); +}