Re: NSTask autorelease OR retain/release -> SIGBUS
Re: NSTask autorelease OR retain/release -> SIGBUS
- Subject: Re: NSTask autorelease OR retain/release -> SIGBUS
- From: Phill Kelley <email@hidden>
- Date: Fri, 4 Apr 2003 11:21:20 +1000
At 23:59 +0000 03/04/2003, Seth Delackner wrote:
>
This should not happen:
>
1. call doFoo. Runs fine.
>
2. call doFoo a second time.
>
a. If on line (A) I autorelease the task, we crash SIGBUS.
>
b. If on line (A) I retain, then at line (B) release, SIGBUS.
>
c. If I simply leave it as listed below, "leaking", it runs fine.
>
>
This isn't the actual code, but it seems to be the relevent portion. The
>
NSTask is not referenced ANYWHERE else in the program.
>
>
foo.m:
>
static NSTask* myTask;
>
>
+ (void)doFoo{
>
NSString* myPath = "/my/binary/path";
>
myTask = [[NSTask alloc] init]; // (A)
>
[myTask setLaunchPath: myPath];
>
[myTask setArguments: [NSArray arrayWithObjects: @"first", nil]];
>
[myTask launch];
>
[myTask waitUntilExit];
>
// (B)
>
myTask = nil;
>
}
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
Here's a working example:
- (void) callHelper
{
int status;
// create a task object
NSTask* task = [[NSTask alloc] init];
// create an array for the arguments
NSMutableArray* taskArguments = [NSMutableArray array];
// add the arguments in order
[taskArguments addObject:[itsPartA stringValue]];
[taskArguments addObject:[itsPartB stringValue]];
[taskArguments addObject:[itsPart1 stringValue]];
[taskArguments addObject:[itsPart2 stringValue]];
[taskArguments addObject:[itsPart3 stringValue]];
[taskArguments addObject:[itsPart4 stringValue]];
// hand the arguments to the task object
[task setArguments:taskArguments];
// set the launch path
[task setLaunchPath:[NSApp ApplicationHelperPath]];
// launch the helper
[task launch];
// wait until it completes
[task waitUntilExit];
// pick up status (which we ignore, for the moment)
status = [task terminationStatus];
// we don't need the task any more
[task release];
}
Apart from minor variations in the way I initialise the objects, and subtle
differences in the ordering of steps, the only two things I see that are
significantly different are the local declaration of the NSTask and the
call to pick up the status result. I have recompiled with a static NSTask
and commenting-out the terminationStatus call but my code still works.
I have not, however, tried rewriting my code as a factory method, so maybe
that has something to do with your problem.
Regards, PK
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.