For example, supose you need to read a file which the program cannot continue executing without it.
You first open the file, then check if it succeeded. Then you somehow get the file size and use it to allocate enought memory. You check it again. Now you are ready to read. If it fails, what do you do?:
1: clear every thing you did before (close the file, free the memory) and exit().
2: just call exit() assuming that the OS will clear everything for you.
I'm asking this because I would love to just call exit(). It is a pain in the ass to always keep looking for things that needs to be cleared if something goes wrong.
I know it is a very simple question, but I would like to know how do you handle this things.