LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
Search this Thread
Old 12-23-2008, 08:23 PM   #1
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,428

Rep: Reputation: 83
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?

What is my best option?

I will appreciate suggestions.

Happy Penguins!
 
Old 12-24-2008, 12:00 AM   #2
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 666

Rep: Reputation: 132Reputation: 132
Quote:
Originally Posted by kaz2100 View Post
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?

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
 
  


Reply

Tags
free, leak, malloc, memory


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
confirmaion for the allocated memory presence chakka.lokesh Programming 2 08-13-2008 11:46 PM
Inactive memory issue, Freebsd (memory leak?) JasperB *BSD 7 08-12-2008 03:19 AM
Freeing memory allocated in a function con Programming 4 01-02-2006 03:25 AM
About allocated memory in C++ Ephracis Programming 2 12-28-2004 02:56 AM
Memory Leak when using memory debugging C program on SuSE SLES8 babalina Linux - Distributions 0 10-06-2003 09:39 AM


All times are GMT -5. The time now is 07:24 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration