Suppose a program has memory leaks.
1) When a process dies (normally or segmentation fault), are those leaked memory freed?
2) What about other resources a process holds?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Stack and heap memory is freed and file descriptors are closed on all modern system, I think.
On POSIX systems there are a number of resources that are not freed when a process exits, shared semaphores, message queues and memory segments. These are meant to be persistent between processes, so they simply can’t. It is the responsibility of the application to free them.
It could do that e.g with
on_exithandlers, but usually there is a simpler way. For memory segments you would typically useshm_unlinkafter all processes have opened such a segment. The segment then ceases to exist when the last process (and its file descriptor to the segment) is closed.