Mechanism like destructors in C?-Collection of common programming errors
C++ uses RAII for managing resource lifetimes.
There is no such mechanism in C, Since you cannot have member functions for structures. Your main concern should be freeing memory allocations for reuse during the lifetime of the program rather than at the end of the lifetime. Once the program ends the OS will reclaim the leaked memory anyways.
Best way to do this in C is, to design your application to take care of lifetimes and code accordingly. This includes careful decision making of whether you really need dynamic memory allocations and if at all the lifetime of the allocated object should be well defined.