-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cow: Make sure to close files after use (#233)
- Loading branch information
Showing
1 changed file
with
7 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,6 +197,7 @@ func (m *manifest) commit(basePath string) error { | |
|
||
// Create new manifest on disk | ||
fNewManifest, err := os.OpenFile(fPath, os.O_CREATE|os.O_RDWR, 0666) | ||
defer fNewManifest.Close() | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -279,6 +280,7 @@ func (m *manifest) commit(basePath string) error { | |
// Overwrite the current manifest number in CURRENT | ||
curFileName := filepath.Join(basePath, "CURRENT") | ||
fCurrent, err := os.OpenFile(curFileName, os.O_CREATE|os.O_WRONLY, 0666) | ||
defer fCurrent.Close() | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -307,6 +309,7 @@ func (m *manifest) load(path string) error { | |
curFileName := filepath.Join(path, "CURRENT") | ||
|
||
curFile, err := os.OpenFile(curFileName, os.O_RDONLY, 0666) | ||
defer curFile.Close() | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -331,6 +334,7 @@ func (m *manifest) load(path string) error { | |
} | ||
|
||
maniFile, err := os.Open(maniFilePath) | ||
defer maniFile.Close() | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -977,6 +981,7 @@ func (cow *cowForest) load(fileNum uint64) error { | |
fmt.Println("FILE LOADED: ", fName) | ||
} | ||
f, err := os.Open(fName) | ||
defer f.Close() | ||
if err != nil { | ||
// If the error returned is of no files existing, then the manifest | ||
// is corrupt | ||
|
@@ -1083,6 +1088,8 @@ func (cow *cowForest) commit() error { | |
if err != nil { | ||
return err | ||
} | ||
|
||
f.Close() | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dergoegge
Author
Contributor
|
||
} | ||
|
||
err := cow.manifest.commit(cow.meta.fBasePath) | ||
|
@dergoegge why are you not using defer here? looks like the handle is leaking unclosed in the two error returns on line 1089 and 1085