Add the file close operation before function return to advoid resource leaking

Signed-off-by: Mabin <bin.ma@huawei.com>
This commit is contained in:
Mabin
2015-02-28 00:24:41 +08:00
parent f5850e8e30
commit b5eeab6e06
+2 -1
View File
@@ -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)
}