3 ms·
The operating system doesn’t handle malloc, realloc and free. That task is handled by the C library. All the operating system provides is a way for these functi
by tinus_hn 6y ago
The operating system doesn’t handle malloc, realloc and free. That task is handled by the C library. All the operating system provides is a way for these functions to claim and release large areas of memory.
Applications use malloc to allocate some memory they then use to store a collection of data. Pointers often don’t point to the exact start of that memory area, which is what you need to do memory management. So from a pointer you can’t necessarily realloc or free.
And the problem is, if a buffer overruns for instance, you end up writing memory that is allocated and valid, just not for the thing the developer thought.
Alternative implementations of malloc exist that try to help with this, by encasing memory between guard pages.
Also, with for example glibc malloc you can use the MALLOC_TRACE environment variable to get a log of all allocations.
- quelsolaar 6y agoI already have an alternative implementation of malloc that does this. But i still need Microsoft s help to get the same information from a process that didn't use my implementation. I dont need to free or realloc pointers i just need to know if a pointer is valid.
- tinus_hn 6y agoIn normal processes you can find this through the _heapwalk function: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/heapwalk?view=msvc-160 https://docs.microsoft.com/en-us/cpp/c-runtime-library/refer...