@@ -581,7 +581,9 @@ CFAllocatorRef CFAllocatorCreate(CFAllocatorRef allocator, CFAllocatorContext *c
581581
582582void * CFAllocatorAllocate (CFAllocatorRef allocator , CFIndex size , CFOptionFlags hint ) {
583583 CFAllocatorAllocateCallBack allocateFunc ;
584- void * newptr = NULL ;
584+ void * newptr ;
585+
586+ if (0 == size ) return NULL ;
585587
586588 if (NULL == allocator ) {
587589 allocator = __CFGetDefaultAllocator ();
@@ -594,17 +596,14 @@ void *CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags
594596#else
595597 __CFGenericValidateType (allocator , _kCFRuntimeIDCFAllocator );
596598#endif
597- if (0 == size ) return NULL ;
598599#if TARGET_OS_MAC
599600 if (_CFTypeGetClass (allocator ) != __CFISAForCFAllocator ()) { // malloc_zone_t *
600601 return malloc_zone_malloc ((malloc_zone_t * )allocator , size );
601602 }
602603#endif
603- newptr = NULL ;
604604 allocateFunc = __CFAllocatorGetAllocateFunction (& allocator -> _context );
605- if (allocateFunc ) {
606- newptr = (void * )INVOKE_CALLBACK3 (allocateFunc , size , hint , allocator -> _context .info );
607- }
605+ if (NULL == allocateFunc ) return NULL ;
606+ newptr = (void * )INVOKE_CALLBACK3 (allocateFunc , size , hint , allocator -> _context .info );
608607 return newptr ;
609608}
610609
@@ -631,11 +630,9 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
631630 return malloc_zone_malloc ((malloc_zone_t * )allocator , newsize );
632631 }
633632#endif
634- newptr = NULL ;
635633 allocateFunc = __CFAllocatorGetAllocateFunction (& allocator -> _context );
636- if (allocateFunc ) {
637- newptr = (void * )INVOKE_CALLBACK3 (allocateFunc , newsize , hint , allocator -> _context .info );
638- }
634+ if (NULL == allocateFunc ) return NULL ;
635+ newptr = (void * )INVOKE_CALLBACK3 (allocateFunc , newsize , hint , allocator -> _context .info );
639636 return newptr ;
640637 }
641638 if (NULL != ptr && 0 == newsize ) {
0 commit comments