diff -r d84d25d6cdbb -r e55a17cdabd2 Target.m --- a/Target.m Sat Mar 08 21:04:41 2008 -0800 +++ b/Target.m Thu Mar 20 09:05:58 2008 -0700 @@ -28,26 +28,30 @@ id $calltarget( NSInvocation *target, id param ) { + id result = nil; if( target && target.target ) { - [target setArgument: ¶m atIndex: 2]; - [target invoke]; - - NSMethodSignature *sig = target.methodSignature; - NSUInteger returnLength = sig.methodReturnLength; - if( returnLength==0 ) - return nil; // void - else { - const char *returnType = sig.methodReturnType; - if( returnType[0]=='@' ) { - id returnObject; - [target getReturnValue: &returnObject]; - return returnObject; + [target retain]; + @try{ + [target setArgument: ¶m atIndex: 2]; + [target invoke]; + + NSMethodSignature *sig = target.methodSignature; + NSUInteger returnLength = sig.methodReturnLength; + if( returnLength==0 ) { + result = nil; // void } else { - UInt8 returnBuffer[returnLength]; - [target getReturnValue: &returnBuffer]; - return [NSValue valueWithBytes: &returnBuffer objCType: returnType]; + const char *returnType = sig.methodReturnType; + if( returnType[0]=='@' ) { + [target getReturnValue: &result]; + } else { + UInt8 returnBuffer[returnLength]; + [target getReturnValue: &returnBuffer]; + result = [NSValue valueWithBytes: &returnBuffer objCType: returnType]; + } } + }@finally{ + [target release]; } - } else - return nil; + } + return result; }