I. Introduction to memory leaks:
1. Frequent memory leaks. The code that occurs in memory leaks is executed multiple times, causing a memory leak each time it is executed.
2. Accidental memory leaks. Code that occurs with a memory leak occurs only under certain circumstances or during operation. The occurrence and the incidental sex are opposite. For a given environment, the occasional may become a frequent occurrence. So test environments and test methods are critical to detecting memory leaks.
3. Disposable memory leaks. The code that occurs with a memory leak is only executed once, or because of an algorithmic flaw, there is always a piece of memory that leaks.
Two. C Program memory leaks and other memory common errors and examples
-
3. Two times for the same address use free ()
4. Make uninitialized data the amount of the assignment
5. The uninitialized value as a condition of judgement
Memory overlap due to 6.memcpy
7. Stack Overflow
8.new, delete, malloc free collocation error
Three. Introduction of memory detection method under Linux
1. Determine the scope to be checked.
2. Detecting a program using the memory Detection tool
At present we use the Open Source Tool under Linux Valgrind for memory leaks and detection of various tools, similar tools are required to re-program at GCC compile time to add the-G parameter, and then can dynamically analyze the program's memory allocation, and various memory errors. Use generally get the result as. (1) Error type (2) The error is located in the file (3) row.
3. Go deep into the source code for error analysis and guessing.
Four. Valgrind Tool Introduction
Memory Leak detection and analysis