No. In C, you have to keep track of what you've allocated yourself.
Some malloc
implementations (such as dlmalloc) provide some extra functionality for inspecting the heap, but you shouldn't rely on those. dlmalloc
has the function dlmalloc_inspect_all
, which will walk the heap and return to you all of the regions of memory that malloc
has allocated, except for memory-mapped chunks. So you could use that to test if a pointer points to a non-memory-mapped allocation, but it's still a bad idea in general.
And on Windows, don't even think about using [IsBadReadPtr
] to test if a pointer points to readable memory or not -- it should really be called CrashProgramRandomly.