@@ -581,7 +581,9 @@ CFAllocatorRef CFAllocatorCreate(CFAllocatorRef allocator, CFAllocatorContext *c
581
581
582
582
void * CFAllocatorAllocate (CFAllocatorRef allocator , CFIndex size , CFOptionFlags hint ) {
583
583
CFAllocatorAllocateCallBack allocateFunc ;
584
- void * newptr = NULL ;
584
+ void * newptr ;
585
+
586
+ if (0 == size ) return NULL ;
585
587
586
588
if (NULL == allocator ) {
587
589
allocator = __CFGetDefaultAllocator ();
@@ -594,17 +596,14 @@ void *CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags
594
596
#else
595
597
__CFGenericValidateType (allocator , _kCFRuntimeIDCFAllocator );
596
598
#endif
597
- if (0 == size ) return NULL ;
598
599
#if TARGET_OS_MAC
599
600
if (_CFTypeGetClass (allocator ) != __CFISAForCFAllocator ()) { // malloc_zone_t *
600
601
return malloc_zone_malloc ((malloc_zone_t * )allocator , size );
601
602
}
602
603
#endif
603
- newptr = NULL ;
604
604
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 );
608
607
return newptr ;
609
608
}
610
609
@@ -631,11 +630,9 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
631
630
return malloc_zone_malloc ((malloc_zone_t * )allocator , newsize );
632
631
}
633
632
#endif
634
- newptr = NULL ;
635
633
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 );
639
636
return newptr ;
640
637
}
641
638
if (NULL != ptr && 0 == newsize ) {
0 commit comments