-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathMemoryMayNotBeFreed.qhelp
More file actions
26 lines (19 loc) · 1015 Bytes
/
MemoryMayNotBeFreed.qhelp
File metadata and controls
26 lines (19 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
This rule looks for functions that allocate memory, but may return without freeing it. This can occur when an operation performed on the memory block fails, and the function returns with an error before freeing the allocated block. This causes the function to leak memory and may eventually lead to software failure.
</p>
<include src="dataFlowWarning.inc.qhelp" />
</overview>
<recommendation>
<p>Ensure that the function frees all dynamically allocated memory it has acquired in all circumstances, unless that memory is returned to the caller.</p>
</recommendation>
<example>
<sample src="MemoryMayNotBeFreed.cpp" />
<p>In this example, if an exception occurs the memory allocated into <code>buff</code> is neither freed or returned. To fix this memory leak, we could add code to free <code>buff</code> to the <code>catch</code> block as follows:</p>
<sample src="MemoryMayNotBeFreedGood.cpp" />
</example>
</qhelp>