This is a good thing, because when something is no longer free, the OS will free it and then free it again, which could be a lot of space.
The malloc and free functions are OS-specific and thus vary from OS to OS. For example, on Windows you can’t free memory from within the same process, and you have to call free() on each memory block individually. It’s basically the same kind of problem you’d see with a hard drive that was previously unallocated but needed to be freed.
I’m not sure there’s an easy answer to what caused malloc to fail. There are many possible reasons. An example is when you have memory that is set to be a certain size and you don’t know how big it is at the time you alloc it. It may be the size of a stack frame, it may be a buffer that is a certain size, it may be a buffer that is set to be a certain size by the OS.
But in this situation I think it is most likely that the program was run out of memory and then the program was terminated or uninstalled prior to the program being able to free the memory.
You can set the memory limit to whatever value you want and then it will not be freed until it is actually needed. That is the best possible scenario. This is exactly what happens in C programs.
And to be a little bit more specific, malloc (which is used to allocate memory) and the free function (which cleans up any memory allocated to a program) are required to be called from within the same routine. A typical example would be the function that creates the file system for the game (in this case, the m_file system).
The code in the m_file system is calling malloc to allocate a chunk of memory for the file system. The malloc function is required to be called from within the same function to ensure that the memory is free’d.
The most common problem we see with pointers in C++ is a call to malloc that results in a call to free which ends up being a call to free. If malloc is called from within a function that is not being called from within the same function as malloc, then the memory allocated to the function and the free function are not being freed at the same time. This is known as stack-allocation memory corruption.
I guess you could say that address 0x0 is not stack’d malloc’d or recently free’d. It’s just a value that represents the address of something else.
It’s also the address on the end of the stack that is currently being allocated, which is why we can’t call malloc there. What’s more, a value of 0x0 might be a value that’s already available at the memory address where we are, so this address doesn’t really represent a memory address.