Files
codeql/ql/src/experimental/InconsistentCode/DeferInLoop.ql
2021-08-12 10:13:30 -07:00

16 lines
479 B
Plaintext

/**
* @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
* @kind problem
* @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"