mirror of
https://github.com/github/codeql.git
synced 2026-01-30 23:02:56 +01:00
Merge pull request #510 from simon-engledew/patch-1
Add an example query for catching cases where defer is used in a loop.
This commit is contained in:
14
ql/examples/snippets/deferinloop.ql
Normal file
14
ql/examples/snippets/deferinloop.ql
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @name Defer in loop
|
||||
* @description A deferred statement in a loop will not execute until the end of the function.
|
||||
* This can lead to unintentionally holding resources open like file handles or database transactions.
|
||||
* @id go/examples/deferinloop
|
||||
* @tags defer
|
||||
* nesting
|
||||
*/
|
||||
|
||||
import go
|
||||
|
||||
from LoopStmt loop, DeferStmt defer
|
||||
where loop.getBody().getAChildStmt+() = defer
|
||||
select defer, "This defer statement is in a $@.", loop, "loop"
|
||||
Reference in New Issue
Block a user