Skip to content

Commit

Permalink
Merge pull request #8 from TimRots/gutil-linux/lspci
Browse files Browse the repository at this point in the history
lspci.go: fix defer
  • Loading branch information
TimRots authored Jan 12, 2021
2 parents 0bb967a + a5a4f53 commit 52c5f20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
all:
@env GOOS=linux GOARCH=amd64 go build -tags all -o bin/lsirq cmd/lsirq/lsirq.go
@env GOOS=linux GOARCH=amd64 go build -tags all -o bin/lspci cmd/lspci/lspci.go
8 changes: 7 additions & 1 deletion cmd/lspci/lspci.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ func readFromFile(f string, w int) string {
func Lookup(searchType, ven, dev, class, subclass string) string {
var found bool = false

// Open pci.ids
f, err := os.Open("./pci.ids")
defer f.Close()
if err != nil {
errCnt++
if errCnt < 2 {
Expand All @@ -196,6 +196,12 @@ func Lookup(searchType, ven, dev, class, subclass string) string {
*numeric = true
return ""
}
// close pci.ids file when done
defer func() {
if err := f.Close(); err != nil {
log.Fatal(err)
}
}()

scanner := bufio.NewScanner(f)
for scanner.Scan() {
Expand Down

0 comments on commit 52c5f20

Please sign in to comment.