This a short snippet of code, with two calls to exit(3) in case of failure.
Do these calls deallocate memory allocated by malloc? Google search once says it does, a
After calling exit you're beyond malloc and friends but the OS reclaims everything. Think of malloc as a convenient intermediary between the OS and your process.