MLK.MUSTMemory leakThe program did not release previously allocated memory and a reference to dynamic memory is lost at this point. Vulnerability and riskMemory leaks cause the application to consume additional memory. This reduces the amount of memory available to other applications and eventually causes the operating system to start paging, slowing the system down. In critical cases, the application will reach overall memory limits, which may result in application crashes. Example 11 class A{ 2 void foo(); 3 }; 4 void A::foo() 5 { 6 int *ptr = new int; 7 *ptr = 25; 8 ptr = new int; 9 *ptr = 35; 10 } Klocwork produces a memory leak report for line 8, indicating that the dynamic memory stored in 'ptr' allocated through the function 'new' at line 6 is lost at line 8. In the above example, another memory leak is reported for line 10: the dynamic memory stored in 'ptr' allocated through the function 'new' at line 8 is lost at line 10. |