Go: Account for deferred Close in writable-file-close query · github/codeql@f67d0ea · GitHub
Skip to content

Commit f67d0ea

Browse files
committed
Go: Account for deferred Close in writable-file-close query
A deferred Close runs at function exit, but the CFG splices it in at the exit node where it can be reached along paths that never execute Sync. The previous dominance check therefore produced a false positive when a statement followed the if-block that registered the defer (e.g. deferredCloseWithSync2). For deferred closes, require instead that a handled Sync post-dominates the point where the defer is registered, which guarantees Sync runs before Close on every path on which Close is registered. Non-deferred closes keep the existing dominance check.
1 parent 5217ede commit f67d0ea

1 file changed

Lines changed: 38 additions & 9 deletions

File tree

‎go/ql/src/InconsistentCode/UnhandledCloseWritableHandle.ql‎

Lines changed: 38 additions & 9 deletions

0 commit comments

Comments
 (0)