Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need some solutions to solve the leaking memory (or buffer overflow problem).

For examples: some tools can automatically detect "buffer overflow problem" in a big program (e.g. with a million code line)

Is there any tools can detect that leak?

Any helps will be sincerely appreciated.
Posted
Comments
Sergey Alexandrovich Kryukov 4-Oct-11 23:33pm    
Why do you think a big program is different from a small one? Strange idea, don't you think so?
--SA
tamcntt1985 4-Oct-11 23:55pm    
Regarding this matter to me, it is easier to look for and detect the leak memory in a small program than the bigger one.

By the way, i will give an easy example that illustrates the problem
For example:
//..
char str1[5];
strcpy(str1, "abcdefghij); // buffer overflow problem appears
//..

Memory leaks in non-managed languages and platforms are notoriously hard to fix and detect without really thorough testing and even then there is a good chance you will miss some.

Having said that check out the following links :
Visual Leak Detector - Enhanced Memory Leak Detection for Visual C++[^]

http://www.linuxjournal.com/article/6556[^]

http://www.softwareverify.com/cpp-memory.php[^]

http://www.cplusplus.com/forum/general/2335/[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Oct-11 1:49am    
Good answer, my 5.

Now, how about buffer overruns? If you think memory leaks are difficult (I think they are relatively simple with the use of tools, based on my experience), how difficult are the buffer overruns? Way more difficult I would say.

I added some information to your solution, please see.
--SA
Simon Bang Terkildsen 5-Oct-11 1:54am    
+5
Malli_S 25-Nov-11 6:09am    
my 5 too.
Mehdi Gholam 25-Nov-11 8:17am    
Cheers
Even though Mehdi refers to a problem of leak detection as difficult, it is actually the easiest of the memory problems to detect. Most complications are related to the mix of different APIs and platforms, different memory models which dominated during the development of C++. All this can of worms still lives in the Windows API.

In the ideal situation, the problem is pretty simple: there is some memory allocation API. A detector hooks up the API, monitors all allocations and deallocations and calculates detailed balance for each object, that's basically it. In many environments, this is 100% reliable. In real life, the main problem is using mixed APIs, but still a leak detectors dig out all the leaky situations.

I would also recommend to look at Visual Leak Detector.
Somewhat more general class of memory tools is the Memory Debugger, see http://en.wikipedia.org/wiki/Memory_debugger[^]. The Memory Debuggers can also address those buffer overrun problems. Please see the memory tools list in the article referenced above.

In contrast to memory leaks, buffer overflow or buffer overrun problems are more difficult, at least with the unsafe way C++ works with pointers and arrays. Please see for more information and the techniques used to overcome the problem: http://en.wikipedia.org/wiki/Buffer_overflow[^].

I'm not personally familiar with the tools effectively helping to overcome the problems of buffer overflow with C++. Again, please look at the list of tools from the article on Memory Debuggers.

—SA
 
Share this answer
 
v2
Comments
Simon Bang Terkildsen 5-Oct-11 1:56am    
My 5, my C++ is way to rusty for me to state a valid opinion on this, though I do remember having a bad memory leak which took me a week to fix.
Sergey Alexandrovich Kryukov 5-Oct-11 2:00am    
Thank you, Simon.
If you C++ code is not yet completely fixed, you have a chance try again or test your memory management -- tools are getting better :-)
--SA
Simon Bang Terkildsen 5-Oct-11 2:06am    
I have no active C++ code at work, but I am creating an alternative to MediaElement backed by FFmpeg, I do all the work with FFmpeg en C++ partly because I wanted to refresh my C++ (I've had to look up even simple syntax a couple of times, really rusty here and it has only been about 5 years :D) When I'm done I'll probably publish an article here on CP unless I find that something something similar already exists.
Sergey Alexandrovich Kryukov 5-Oct-11 2:40am    
Would be interesting to see. Please notify me when you publish it.
--SA
Mehdi Gholam 5-Oct-11 2:02am    
Ever the complete answer!
The only addition I would make is that the difficulty arises from the language as it bars nothing and allows you to do anything, how many ways to create and use a "string" for example.
Since there is no standardization to speak of the poor tool must use some advanced AI.
I'm not aware of any useful free or shareware tools of that kind, especially ones that go beyond memory leak detection. There are a few commercial products though, with prices in the 4-5 digits. And, IME, you might want to have or purchase an extra machine to run this tool on as it's incredibly time-consuming.

Rational Software tools might be among the most prominent, but also the most costly. I've found Parasoft Insure++ to be reasonably priced, although still a bit steep just for personal use. I'm sure there are others, but last I checked was 2008, so you may be able to find more than I ever could.
 
Share this answer
 
Oh! I spent much time studying this problem. Memory leak are not visible at first. Then it is a big problem. As for me, I use deleaker. It will help you find the leaks and localize them. Then we can consider how to deal with them.
 
Share this answer
 
If you're in a Windows environment, Microsoft has a free tool called Application Verifier[^] that does a number of runtime checks including memory leak detection.

-PaulH
 
Share this answer
 
Hi,

Download and install Memory validator evaluation version.
 
Share this answer
 
Look at my solution in the link Memory leakage detection[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900