@@ -24,31 +24,31 @@ class_copyIvarList(Class class, unsigned int *outCount) { unsigned int count; Ivar *ivars; - if (class == Nil) - return NULL; + if (class == Nil) { + if (outCount != NULL) + *outCount = 0; - objc_global_mutex_lock(); - - if (class->ivars == NULL) { - objc_global_mutex_unlock(); return NULL; } - count = class->ivars->count; + objc_global_mutex_lock(); + + count = (class->ivars != NULL ? class->ivars->count : 0); if (count == 0) { + if (outCount != NULL) + *outCount = 0; + objc_global_mutex_unlock(); return NULL; } - if ((ivars = malloc((count + 1) * sizeof(Ivar))) == NULL) { - objc_global_mutex_unlock(); - return NULL; - } + if ((ivars = malloc((count + 1) * sizeof(Ivar))) == NULL) + OBJC_ERROR("Not enough memory to copy ivars"); for (unsigned int i = 0; i < count; i++) ivars[i] = &class->ivars->ivars[i]; ivars[count] = NULL;