Problem
1. File descriptor leak in pkg/fanal/artifact/vm/file.go
In the newFile() function (line 39), a file is opened:
f, err := os.Open(filePath)
When errors occur on lines 46, 52, or 60, the function returns without closing the file descriptor, causing a resource leak.
2. Pipe resource leak in pkg/flag/options.go
In the outputPluginWriter() function (line 585), pipes are created:
When an error occurs on line 591, the function returns without closing these pipe resources.
Impact
Resources are not properly closed on error paths, leading to potential resource leaks.
Solution
Implement proper cleanup using defer statements with named error returns to ensure resources are closed on all error paths.
References
Problem
1. File descriptor leak in
pkg/fanal/artifact/vm/file.goIn the
newFile()function (line 39), a file is opened:When errors occur on lines 46, 52, or 60, the function returns without closing the file descriptor, causing a resource leak.
2. Pipe resource leak in
pkg/flag/options.goIn the
outputPluginWriter()function (line 585), pipes are created:When an error occurs on line 591, the function returns without closing these pipe resources.
Impact
Resources are not properly closed on error paths, leading to potential resource leaks.
Solution
Implement proper cleanup using defer statements with named error returns to ensure resources are closed on all error paths.
References