Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed memory leaks in expectations and matchers #28

Merged
merged 1 commit into from

2 participants

@pivotaltracker

We used Instruments to profile our specs after leaked objects began to cause test pollution. We tracked the issue down to both the expect() macro and any matcher that took a parameter, such as equal().

For example:

expect(myObject).toNot.beNil()

will leak my object because the -[EXPExpect actualBlock] property is not released when the expectation is released.

The matcher in this assertion also leaks:

expect(nil).toNot.equal(myObject)

because the EXPBlockDefinedMatcher does not release any of the blocks it retains.

There were also a pair of other simple memory management bugs which we fixed:

  • the block returned from -[EXPDynamicPredicateMatcher dispatch] was not autoreleased
  • The dynamic matcher methods created by _EXPMatcherImplementationBegin would not release the EXPBlockDefinedMatcher *matcher

Cheers,

Christian and Ted

@petejkim
Owner

thanks!!! i didn't catch those merging pull requests

@petejkim petejkim merged commit abc3d83 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 7, 2013
  1. Fixed memory leaks in expectations and matchers

    Christian Niles and Ted Young authored
This page is out of date. Refresh to see the latest.
View
10 src/EXPBlockDefinedMatcher.m
@@ -10,6 +10,16 @@
@implementation EXPBlockDefinedMatcher
+- (void)dealloc
+{
+ self.prerequisiteBlock = nil;
+ self.matchBlock = nil;
+ self.failureMessageForToBlock = nil;
+ self.failureMessageForNotToBlock = nil;
+
+ [super dealloc];
+}
+
@synthesize prerequisiteBlock;
@synthesize matchBlock;
@synthesize failureMessageForToBlock;
View
10 src/EXPExpect.m
@@ -37,6 +37,12 @@ - (id)initWithActualBlock:(id)actualBlock testCase:(id)testCase lineNumber:(int)
return self;
}
+- (void)dealloc
+{
+ self.actualBlock = nil;
+ [super dealloc];
+}
+
+ (EXPExpect *)expectWithActualBlock:(id)actualBlock testCase:(id)testCase lineNumber:(int)lineNumber fileName:(char *)fileName {
return [[[EXPExpect alloc] initWithActualBlock:actualBlock testCase:(id)testCase lineNumber:lineNumber fileName:fileName] autorelease];
}
@@ -186,9 +192,9 @@ - (NSString *)failureMessageForNotTo:(id)actual
{
__block id blockExpectation = _expectation;
- return [^{
+ return [[^{
[blockExpectation applyMatcher:self];
- } copy];
+ } copy] autorelease];
}
@end
View
1  src/ExpectaSupport.h
@@ -42,6 +42,7 @@ EXPFixCategoriesBug(EXPMatcher##matcherName##Matcher); \
} \
[self applyMatcher:matcher to:&actual]; \
}; \
+ [matcher release]; \
return [[matcherBlock copy] autorelease]; \
} \
@end
Something went wrong with that request. Please try again.