Yes, all memory is back. BTW, what would you like to do with the remaining memory after exiting anyway?
Or are you worried about memory leak in exit() ? If the memory had not been recovered, this would have leaked a little more with each outgoing process, which no credible OS could allow. Therefore, with the exception of the OS buggy, stop worrying about memory and use exit() where you need it.
In order to answer the questions in the comments of your code, whether for free, I would say that the correct software development is to write the corresponding free with each malloc . If this is complicated, this indicates a structural problem in your code. The advantage of freeing up all memory before exiting is that you can use powerful tools like valgrind to check for memory leaks in the rest of your code without the false positives from malloc that you showed us.
Note that after a failed malloc, it makes no sense to try to free the result - in any case, this is a null pointer.
And thirdly, I prefer if (pointer == NULL) over if (!pointer) , but this is completely subjective, and I can read and understand both :-)
Jens
source share