Skip to content

Fix HANDLE_LEAK.EX in aulast.c#511

Merged
stevegrubb merged 1 commit intolinux-audit:masterfrom
mikhailnov:svace6
Feb 28, 2026
Merged

Fix HANDLE_LEAK.EX in aulast.c#511
stevegrubb merged 1 commit intolinux-audit:masterfrom
mikhailnov:svace6

Conversation

@mikhailnov
Copy link
Contributor

Close file handle 'f' before returning error in argument parsing to prevent resource leak when --extract option is followed by an invalid argument.

Svace report:
Handle 'f' is created at aulast.c:506 by calling function 'fopen'
and lost at aulast.c:506. (CWE404, CWE775)

This leaks happens in the end of main() and could be not fixed, but let's make static analyzers happy...

Example scaniors of leaks:
aulast --extract -f file -f file2
aulast -f file --extract --stdin
aulast --extract --user u1 --user u2
aulast --extract --tty t1 --tty t2
aulast --extract --invalid

Close file handle 'f' before returning error in argument parsing
to prevent resource leak when --extract option is followed by
an invalid argument.

Svace report:
  Handle 'f' is created at aulast.c:506 by calling function 'fopen'
  and lost at aulast.c:506. (CWE404, CWE775)

This leaks happens in the end of main() and could be not fixed, but let's make static analyzers happy...

Example scaniors of leaks:
  aulast --extract -f file -f file2
  aulast -f file --extract --stdin
  aulast --extract --user u1 --user u2
  aulast --extract --tty t1 --tty t2
  aulast --extract --invalid

Co-authored-by: Z.AI GLM-5
@stevegrubb stevegrubb merged commit ec9ab85 into linux-audit:master Feb 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants