Open J3oss opened 2 years ago
Currently, we have no way to check for memory leaks except through the usage of valgrind, which doesn't work on Windows. Since that's the case, we should add a layer between our call to ev_malloc
and the actual malloc
function call. Within this layer, we'll be storing each allocation's data (allocation name, file, line, address, ..etc.) until it is free'd. When the program execution ends and we still have some stored allocation data, those are reported as memory leaks that need to be fixed.
Some pseudo-code:
void* __ev_malloc_internal(struct allocation allocData)
{
allocData.ptr = malloc(allocData.size);
store_allocation(allocData.ptr, allocData);
return allocData.ptr
}
void __ev_free_internal(void* ptr)
{
remove_allocation(ptr);
free(ptr);
}
int destroy_memory()
{
if(allocation_count() != 0) {
report_memory_leaks();
return -1;
}
return 0;
}
Other headers that this one probably depends on:
This will introduce ev_malloc and ev_free.