Skip to content

Commit bcb7901

Browse files
authored
Merge pull request github#18111 from jketema/guarded-free
C++: Promote `cpp/guarded-free` out of experimental
2 parents 47487cc + 6d37efc commit bcb7901

File tree

8 files changed

+20
-7
lines changed

8 files changed

+20
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
<!DOCTYPE qhelp SYSTEM "qhelp.dtd">
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
24
<qhelp>
5+
36
<overview>
4-
<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>
7+
<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 the 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.</p>
18+
1119
</example>
20+
1221
<references>
1322
<li>
1423
The Open Group Base Specifications Issue 7, 2018 Edition:
15-
<a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html">free - free allocated memory</a>
24+
<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
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: newQuery
3+
---
4+
* Added a new high-precision quality query, `cpp/guarded-free`, which detects useless NULL pointer checks before calls to `free`. A variation of this query was originally contributed as an [experimental query by @mario-campos](https://github.com/github/codeql/pull/16331).

cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/GuardedFree.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Best Practices/GuardedFree.ql

0 commit comments

Comments
 (0)