Fix memory leak in @synchronized.

This was actually a memory leak in the hidden class implementation, but
it was mostly visible in the @synchronized implementation.  Every hidden
class registered a custom .cxx_destruct method, to handle cleanup of all
of the hidden class structures.  Unfortunately, this destructor failed
to delete the reflection metadata structures associated with the class,
specifically the objc_method_list containing the objc_method pointing to
the destructor itself.

Fixes #98
main
David Chisnall 7 years ago
parent c5fbeb7287
commit bd5637af6d

@ -275,6 +275,9 @@ static void deallocHiddenClass(id obj, SEL _cmd)
}
}
obj->isa = hiddenClass->super_class;
// Free the introspection structures:
freeMethodLists(hiddenClass);
freeIvarLists(hiddenClass);
// Free the class
free(hiddenClass);
}

@ -434,4 +434,13 @@ static inline BOOL classIsOrInherits(Class cls, Class base)
return NO;
}
/**
* Free the instance variable lists associated with a class.
*/
void freeIvarLists(Class aClass);
/**
* Free the method lists associated with a class.
*/
void freeMethodLists(Class aClass);
#endif //__OBJC_CLASS_H_INCLUDED

@ -622,7 +622,7 @@ id objc_getRequiredClass(const char *name)
return cls;
}
static void freeMethodLists(Class aClass)
PRIVATE void freeMethodLists(Class aClass)
{
struct objc_method_list *methods = aClass->methods;
while(methods != NULL)
@ -637,7 +637,7 @@ static void freeMethodLists(Class aClass)
}
}
static void freeIvarLists(Class aClass)
PRIVATE void freeIvarLists(Class aClass)
{
struct objc_ivar_list *ivarlist = aClass->ivars;
if (NULL == ivarlist) { return; }

Loading…
Cancel
Save