mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-14 17:01:22 +00:00
8385046486
Forgetting to invoke [super dealloc] in a derived class's -dealloc method has caused me to waste far too much time chasing down the resulting memory leaks and crashes. This is actually the main focus of issue #24, but I want to take care of multiple paths before I consider the issue to be done. However, as a bonus, four cases were found :)
44 lines
801 B
R
44 lines
801 B
R
@interface Object
|
|
{
|
|
Class isa;
|
|
}
|
|
-(void)dealloc;
|
|
-(void)release;
|
|
@end
|
|
|
|
@interface derived : Object
|
|
{
|
|
id something;
|
|
}
|
|
@end
|
|
|
|
@implementation Object
|
|
-(void) dealloc
|
|
{
|
|
// this is the root of the hierarchy, so no super to call, thus
|
|
// must not check for [super dealloc]
|
|
}
|
|
-(void) release
|
|
{
|
|
}
|
|
@end
|
|
|
|
@implementation derived
|
|
-(void) dealloc
|
|
{
|
|
// as this is a derived class, failure to call [super dealloc] will
|
|
// result in a memory leak (yes, there could be special allocators
|
|
// involved, in which case something will be needed to inform the
|
|
// compiler)
|
|
[super release];
|
|
[something dealloc];
|
|
}
|
|
@end
|
|
|
|
void __obj_exec_class (struct obj_module *msg) = #0;
|
|
id obj_msgSend_super (Super *class, SEL op, ...) = #0;
|
|
|
|
int main ()
|
|
{
|
|
return 1; // test fails if compile succeeds (with -Werror)
|
|
}
|