Merge pull request #11054 from MabinGo/checkfileoper1
Add the file close operation before function return to advoid resource leaking
This commit is contained in:
commit
82aa950f4e
1 changed files with 2 additions and 1 deletions
|
@ -55,13 +55,14 @@ func ProbeFsType(device string) (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
buffer := make([]byte, maxLen)
|
||||
l, err := file.Read(buffer)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
file.Close()
|
||||
|
||||
if uint64(l) != maxLen {
|
||||
return "", fmt.Errorf("unable to detect filesystem type of %s, short read", device)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue