diff --git a/Source/OCMockito/Invocation/NSInvocation+OCMockito.m b/Source/OCMockito/Invocation/NSInvocation+OCMockito.m index ed832e06..0cd78e03 100644 --- a/Source/OCMockito/Invocation/NSInvocation+OCMockito.m +++ b/Source/OCMockito/Invocation/NSInvocation+OCMockito.m @@ -15,6 +15,8 @@ @implementation NSInvocation (OCMockito) - (NSArray *)mkt_arguments { + [self retainArguments]; // make sure no stack blocks are added to the autoreleased array that can outlive them + NSMethodSignature *signature = self.methodSignature; NSUInteger numberOfArguments = signature.numberOfArguments; NSMutableArray *arguments = [NSMutableArray arrayWithCapacity:numberOfArguments - 2]; diff --git a/Source/Tests/NSInvocation+OCMockitoTests.m b/Source/Tests/NSInvocation+OCMockitoTests.m index 21a353a8..402d02d7 100644 --- a/Source/Tests/NSInvocation+OCMockitoTests.m +++ b/Source/Tests/NSInvocation+OCMockitoTests.m @@ -63,4 +63,11 @@ - (void)testRetainArgumentsWithWeakTarget_ShouldNotReplaceTargetOnSecondCall assertThat([invocation target], is(sameInstance(weakProxy))); } +- (void)testArguments_ShouldCopyStackBlocks +{ + assertThat(@(invocation.argumentsRetained), isFalse()); + [invocation mkt_arguments]; + assertThat(@(invocation.argumentsRetained), isTrue()); +} + @end