Fix dangling reference in weak ref code.

Another test added as a result of coverage analysis.
main
David Chisnall 8 years ago
parent 8021533d4c
commit ca1d45a4e6

@ -0,0 +1,35 @@
#import "Test.h"
id __weak var;
@interface ARC : Test @end
@implementation ARC
- (id)loadWeak
{
return var;
}
- (void)setWeakFromWeak: (id __weak)anObject
{
var = anObject;
}
- (void)setWeak: (id)anObject
{
var = anObject;
}
@end
int main(void)
{
ARC *obj = [ARC new];
{
id o1 = [Test new];
id o2 = [Test new];
[obj setWeak: o1];
assert([obj loadWeak] == o1);
[obj setWeakFromWeak: o2];
assert([obj loadWeak] == o2);
}
assert([obj loadWeak] == nil);
return 0;
}

@ -7,6 +7,7 @@
set(TESTS set(TESTS
alignTest.m alignTest.m
AllocatePair.m AllocatePair.m
ARCTest_arc.m
AssociatedObject.m AssociatedObject.m
AssociatedObject2.m AssociatedObject2.m
BlockImpTest.m BlockImpTest.m

@ -671,6 +671,7 @@ static inline BOOL weakRefRelease(WeakRef *ref)
ref->weak_count--; ref->weak_count--;
if (ref->weak_count == 0) if (ref->weak_count == 0)
{ {
weak_ref_remove(weakRefs, ref->obj);
free(ref); free(ref);
return YES; return YES;
} }

Loading…
Cancel
Save