Skip to content

Commit d9b278d

Browse files
committed
C++: Promote cpp/guarded-free
1 parent d73dcd6 commit d9b278d

File tree

6 files changed

+14
-5
lines changed

6 files changed

+14
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
<!DOCTYPE qhelp SYSTEM "qhelp.dtd">
2-
<qhelp>
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp><qhelp>
5+
36
<overview>
47
<p>The <code>free</code> function, which deallocates heap memory, may accept a NULL pointer and take no action. Therefore, it is unnecessary to check its argument for the value of NULL before a function call to <code>free</code>. As such, these guards may hinder performance and readability.</p>
58
</overview>
9+
610
<recommendation>
7-
<p>A function call to <code>free</code> should not depend upon the value of its argument. Delete the <code>if</code> condition preceeding a function call to <code>free</code> when its only purpose is to check the value of the pointer to be freed.</p>
11+
<p>A function call to <code>free</code> should not depend upon the value of its argument. Delete the condition preceding a function call to <code>free</code> when its only purpose is to check the value of the pointer to be freed.</p>
812
</recommendation>
13+
914
<example>
1015
<sample src = "GuardedFree.cpp" />
16+
17+
<p>In this example the condition checking the value of <code>foo</code> can be deleted.
18+
1119
</example>
20+
1221
<references>
1322
<li>
1423
The Open Group Base Specifications Issue 7, 2018 Edition:
1524
<a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html">free - free allocated memory</a>
1625
</li>
1726
</references>
18-
</qhelp>
27+
28+
</qhelp>

cpp/ql/src/experimental/Best Practices/GuardedFree.ql renamed to cpp/ql/src/Best Practices/GuardedFree.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @id cpp/guarded-free
99
* @tags maintainability
1010
* readability
11-
* experimental
1211
*/
1312

1413
import cpp

0 commit comments

Comments
 (0)