Kaynağa Gözat

coalesce(): next_block should not be checked if it is free when it is NULL

Ioannis Koutras 13 yıl önce
ebeveyn
işleme
076a4ed1f3
1 değiştirilmiş dosya ile 6 ekleme ve 4 silme
  1. 6 4
      src/coalesce.c

+ 6 - 4
src/coalesce.c

@@ -77,16 +77,18 @@ bool coalesce(allocator_t *allocator, heap_t *heap, void *ptr) {
     }
 
     /* Previous + Current + Next */
-    if(next_block != NULL && is_previous_free(ptr) && is_free(next_block)) {
+    if(next_block != NULL) {
+        if(is_previous_free(ptr) && is_free(next_block)) {
 #ifdef WITH_OWNERSHIP
-        if(get_owner(ptr) == get_owner(previous_block) &&
-            get_owner(ptr) == get_owner(next_block)) {
+            if(get_owner(ptr) == get_owner(previous_block) &&
+                    get_owner(ptr) == get_owner(next_block)) {
 #endif /* WITH_OWNERSHIP */
                 three_blocks_size = get_previous_size(ptr) + size +
                     get_size(next_block) + 2 * HEADER_SIZE;
 #ifdef WITH_OWNERSHIP
-        }
+            }
 #endif /* WITH_OWNERSHIP */
+        }
     } else {
         three_blocks_size = (size_t) -1; /* SIZE_MAX */
     }