-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poor errors handling and memory management #17
Comments
- (void)collectClasses
{
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
uint classesCount;
const char *imageName = class_getImageName(object_getClass(self));
const char **classNames = objc_copyClassNamesForImage(imageName, &classesCount);
for (uint index = 0; index < classesCount; index++) {
Class nextClass = objc_getClass(classNames[index]); // what if push_back() throws an exception? // you'll never reach ::free() statement }
free(classNames); |
Premature optimization? |
I understand what you mean, but, IMHO, there a lot of cases when something might be broken, should we cover all them? Anyway, if you see a big problem with this part of code - feel free to send a PR. |
It's not about optimizations. It's rather about proper resources management (memory) and avoiding crashes.
Nothing since it is safe to send messages to a |
Critical crashes should be addressed in no doubt. |
Thank you, I've got your point and will check and fix such issues. |
7.20.3.2 The free function Synopsis #include <stdlib.h> The free function causes the space pointed to by ptr to be deallocated, that is, made available for further allocation. If ptr is a null pointer, no action occurs. See ISO-IEC 9899. |
For example :
// What makes you sure "protocols" variable is not NULL ?
free(protocols);
The text was updated successfully, but these errors were encountered: