Просмотр исходного кода

Correct fix to `heap_allocator_proc` in compiler

gingerBill 4 лет назад
Родитель
Сommit
97a1147537
1 измененных файлов с 7 добавлено и 11 удалено
  1. 7 11
      src/common_memory.cpp

+ 7 - 11
src/common_memory.cpp

@@ -351,20 +351,19 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
 	} break;
 	} break;
 
 
 	case gbAllocation_Free:
 	case gbAllocation_Free:
-		if (!old_memory) {
+		if (old_memory != nullptr) {
 			free(old_memory);
 			free(old_memory);
 		}
 		}
 		break;
 		break;
 
 
 	case gbAllocation_Resize:
 	case gbAllocation_Resize:
-		if (!old_memory) {
-			break;
-		}
 		if (size == 0) {
 		if (size == 0) {
-			free(old_memory);
+			if (old_memory != nullptr) {
+				free(old_memory);
+			}
 			break;
 			break;
 		}
 		}
-		if (!old_memory) {
+		if (old_memory == nullptr) {
 			ptr = aligned_alloc(alignment, (size + alignment - 1) & ~(alignment - 1));
 			ptr = aligned_alloc(alignment, (size + alignment - 1) & ~(alignment - 1));
 			gb_zero_size(ptr, size);
 			gb_zero_size(ptr, size);
 			break;
 			break;
@@ -386,20 +385,17 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
 		break;
 		break;
 
 
 	case gbAllocation_Free:
 	case gbAllocation_Free:
-		if (!old_memory) {
+		if (old_memory != nullptr) {
 			free(old_memory);
 			free(old_memory);
 		}
 		}
 		break;
 		break;
 
 
 	case gbAllocation_Resize:
 	case gbAllocation_Resize:
-		if (!old_memory) {
-			break;
-		}
 		if (size == 0) {
 		if (size == 0) {
 			free(old_memory);
 			free(old_memory);
 			break;
 			break;
 		}
 		}
-		if (!old_memory) {
+		if (old_memory == nullptr) {
 			posix_memalign(&ptr, alignment, size);
 			posix_memalign(&ptr, alignment, size);
 			gb_zero_size(ptr, size);
 			gb_zero_size(ptr, size);
 			break;
 			break;