In C, if I allocate a memory using malloc and during the execution, the program encounters an exception/error and exits with a manually incorporated exit(1) statement in the program, does C compiler automatically frees the memory before making the unexpected exit or do I have to manually do this just before the exit(1) line in the program.
I use the gcc-4.5.2 compiler on Ubuntu 32bit platform.
Once you call
exit, OS takes all the allocated memory back. So no need to callfree.Edit:
But It’s generally good practice to free memory you allocated in your program as you may overlook it the call to free when you modify it in the future.