[SOLVED] Memory leak: How risky not to free allocated memory.
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Memory leak: How risky not to free allocated memory.
Hya,
background:
I am revising old program, (not coded by me) which does not compile without -fwritable-string. These days, gcc does not accept this option. (ANSI string is const, so cannot modify. With that option, gcc-3 used to allocate writable memory for string, so that can be overwritten. It is a violation of ANSI rulebook.)
Program is a small pipe. I have no idea how much memory is allocated.
So far, I have done:
I managed to allocate necessary memory for these variables, copy into and and program itself look good.
So far, I have not done:
However, modifications happened all over the place, and I have not figured out overall program structure. At this moment, none of allocated memory is freed. I know it is not good, but not easy to keep track.
Web search:
Web says that modern OS takes care of allocated memory requested by program when the program exits. Another Web says not freeing allocated memory is a good way to make memory leak.
Question:
If the former is correct, every time this program finishes, memory is freed, so my penguin stays healthy. If the latter, my penguin may get sick. Do I need to spend another three days to take care of allocated memory?
background:
I am revising old program, (not coded by me) which does not compile without -fwritable-string. These days, gcc does not accept this option. (ANSI string is const, so cannot modify. With that option, gcc-3 used to allocate writable memory for string, so that can be overwritten. It is a violation of ANSI rulebook.)
Program is a small pipe. I have no idea how much memory is allocated.
So far, I have done:
I managed to allocate necessary memory for these variables, copy into and and program itself look good.
So far, I have not done:
However, modifications happened all over the place, and I have not figured out overall program structure. At this moment, none of allocated memory is freed. I know it is not good, but not easy to keep track.
Web search:
Web says that modern OS takes care of allocated memory requested by program when the program exits. Another Web says not freeing allocated memory is a good way to make memory leak.
Question:
If the former is correct, every time this program finishes, memory is freed, so my penguin stays healthy. If the latter, my penguin may get sick. Do I need to spend another three days to take care of allocated memory?
What is my best option?
I will appreciate suggestions.
Happy Penguins!
Both WEB correct. If your program is "short living", i.e it's aloocate memory, do whatever it do and then exist, then it is no real harm in not freeing allocated memory - OS will take care. If on the other hand, program is long standing one, i.e it do same operation and each time allocate and never freed memory - it's a bad thing, and should be fixed
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.