Question: Is there any mechanism like destructors in C? Or is there another way to achieve it?

My requirement is that when a program terminates all memory allocated at runtime should be freed. I keep a list of memory that is allocated using `malloc`.

Answer: 
The operating system will take care of this. When a program terminates, the OS will reclaim all memory used by the process.
At application termination all memory allocated through malloc() will be freed unless the application becomes some kind of a zombie process. Normal termination should free all space otherwise.

The malloc() function uses operating system calls to allocate memory and when the process terminates the memory allocated to the process is reclaimed by the operating system.

I have seen cases of zombie processes under Windows in which a process stayed in memory hanging around until it was terminated via the Task Manager application.