Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

Commit

Permalink
dockertar-sha256-helper: Defer Close
Browse files Browse the repository at this point in the history
Defer Close calls to ensure closing at the end of the function.

Signed-off-by: Steve Milner <[email protected]>

Closes: #1117
Approved by: giuseppe
  • Loading branch information
ashcrow authored and rh-atomic-bot committed Oct 16, 2017
1 parent eced7be commit 6dddc4c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dockertar-sha256-helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ func main() {
panic("One positional argument is required")
}
reader, err := os.Open(os.Args[1])
// Close the input file at the end of the function
defer reader.Close()
if err != nil {
os.Exit(1)
}
Expand All @@ -33,7 +35,8 @@ func main() {
panic(err)
}
}
// We must explicitly close before executing the sum
// as defer will cause an incorrect result
w.Close()

fmt.Printf("%x\n", sha_256.Sum(nil))
}

0 comments on commit 6dddc4c

Please sign in to comment.