Based on the formulation of this question, it appears you're trying to reinvent an algorithm not unlike mark-sweep for garbage collection using glibc. The effort is noble, but garbage collectors exist to meet this need quite tidily, and referring to them will save you a tremendous amount of reimplementation effort if this is indeed your ultimate goal.
Meanwhile, the functionality you desire doesn't exist in the C specification, and implementing it in glibc is somewhat difficult and hacky. You'll want to consult your local glibc's version of malloc/malloc.c
to determine the correct strategy if you desire to continue moving forward with your implementation, on account of different versions providing very different allocator-level guarantees. It can be done by piggybacking code on the allocator, but this doesn't seem to be the ideal solution to your expressed problem.
Despite being steeped in C++, this thread contains a treasure trove of information on how to write your own memory manager and how to evaluate a good reference implementation, which is a more workable strategy if you don't want to tether yourself to the internals of glibc. I would highly advise this strategy, because it future-proofs your application and abstracts away the functionality you desire (thus allowing you to drop in a different C library in the future).
Best of luck with your application(s).