Dynamically allocated (malloc) memory is returned back to the OS when a
program terminates normally. But what if the program crashes? Is its heap also freed? Thanks.
That depends entirely on the OS. The C++ standard has nothing to say
on the matter -- wrong jurisdiction. However, generally speaking, yes,
most OSes will reclaim all such memory.