erikdoe/ocmock — pull request #137 by plivesey (2014-08-20 00:05:07+00:00)
Title: Fixing a crash caused by an autorelease pool.

We want to make sure we don't release return values for NSInvocations before they are used.

This is a fix for a bug that I found today. It looks like `indexOfObjectPassingTest` creates an autorelease pool when iterating. Since return values for NSInvocations can be captured in this pool, the return values could be released before they are used, which would cause a crash.

As far as I can see, there is no other way of writing the mocking code below for all cases. My current workaround is to create a retain cycle so the object never gets dealloced, avoiding the crash. I don't think this is a good solution.

Note: this only happens in specific situations where you use a mock within another mock context. However, I think the use case is valid and OCMock should handle it correctly. The crash is reproducible and happens every time.

I've included a unit test which fails before I make the change to OCMockObject and passes afterwards.

Thanks.