소스 검색

order of special checks matters

The order of special checks seems critical for some applications.
Xorg 1.18.0 fails to start with XNFreallocarray error.
Took me some time to run with MALLOC_DEBUG=2 to find out.
MALLOC_STANDARD is not affected.
Waldemar Brodkorb 8 년 전
부모
커밋
cddda5f9be
1개의 변경된 파일4개의 추가작업 그리고 2개의 파일을 삭제
  1. 4 2
      libc/stdlib/malloc/realloc.c

+ 4 - 2
libc/stdlib/malloc/realloc.c

@@ -26,14 +26,16 @@ realloc (void *mem, size_t new_size)
   size_t size;
   char *base_mem;
 
+  if (! mem)
+    return malloc (new_size);
+
   /* Check for special cases.  */
   if (! new_size)
     {
       free (mem);
       return NULL;
     }
-  if (! mem)
-    return malloc (new_size);
+
   /* This matches the check in malloc() */
   if (unlikely(((unsigned long)new_size > (unsigned long)(MALLOC_HEADER_SIZE*-2))))
     return NULL;