Changed size_query and destructor call order

This commit is contained in:
VegOwOtenks 2024-10-16 17:18:14 +02:00
parent bc49570d12
commit c6ff6ad31d

View file

@ -29,8 +29,8 @@ int TracingHeap_Create(TracingHeap* self, allocator_t* allocator)
static void _TracingHeap_ForceDestroyObject(TracingHeap* self, TracingObject* object) static void _TracingHeap_ForceDestroyObject(TracingHeap* self, TracingObject* object)
{ {
self->config.destructor(self->config.destructor_context, object->data);
size_t allocated_size = self->config.size_query(self->config.size_query_context, object->data); size_t allocated_size = self->config.size_query(self->config.size_query_context, object->data);
self->config.destructor(self->config.destructor_context, object->data);
Allocator_Free(self->allocator, object, allocated_size); Allocator_Free(self->allocator, object, allocated_size);
} }
@ -166,13 +166,13 @@ size_t TracingHeap_TraceNextN(TracingHeap* self, size_t n)
static int _TracingHeap_DestroyObject(TracingHeap* self, TracingObject* unreachable_object) static int _TracingHeap_DestroyObject(TracingHeap* self, TracingObject* unreachable_object)
{ {
size_t allocated_size = self->config.size_query(self->config.size_query_context, unreachable_object->data);
int destructor_code = self->config.destructor(self->config.destructor_context, unreachable_object->data); int destructor_code = self->config.destructor(self->config.destructor_context, unreachable_object->data);
if (destructor_code) { if (destructor_code) {
return destructor_code; return destructor_code;
} }
size_t allocated_size = self->config.size_query(self->config.size_query_context, unreachable_object->data);
Allocator_Free(self->allocator, unreachable_object, allocated_size); Allocator_Free(self->allocator, unreachable_object, allocated_size);
return EXIT_SUCCESS; return EXIT_SUCCESS;