I have written a C program containing code allocating memory using the
malloc() function. If I don't free up the memory using the
free() function, will Ubuntu release it automatically?
The kernel will release all the resources allocated by a program upon the program's termination.
This is done after the
do_exit() function defined in
kernel/exit.c has terminated its execution; the
do_exit() function execution itself might be triggered by a number of events, most commonly by an explicit
exit() syscall called by the program during its regular computation or by an implicit
exit() syscall called by the program upon its termination (as the C compiler places an
exit() syscall after
main()'s return). Other reasons include the reception of an unhandable / not ignorable signal or exception.
do_exit() function itself performs a number of tasks. After it has terminated its execution, the program's allocated resources are released by the kernel and returned to the system for further uses.