Move checked_malloc out of main.cpp.

Check_malloc declaration and definition are moved to a more suitable
place. Add Doxygen comments to the declaration and definition.