mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-17 20:40:26 +09:00
Fix potential file leaks (#1958)
This commit is contained in:
@@ -216,17 +216,18 @@ func NewBufferFromFileAtLoc(path string, btype BufType, cursorLoc Loc) (*Buffer,
|
||||
readonly := os.IsPermission(err)
|
||||
f.Close()
|
||||
|
||||
file, err := os.Open(filename)
|
||||
fileInfo, serr := os.Stat(filename)
|
||||
if serr != nil && !os.IsNotExist(serr) {
|
||||
return nil, serr
|
||||
}
|
||||
|
||||
if err == nil && fileInfo.IsDir() {
|
||||
if serr == nil && fileInfo.IsDir() {
|
||||
return nil, errors.New("Error: " + filename + " is a directory and cannot be opened")
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
file, err := os.Open(filename)
|
||||
if err == nil {
|
||||
defer file.Close()
|
||||
}
|
||||
|
||||
var buf *Buffer
|
||||
if os.IsNotExist(err) {
|
||||
|
||||
Reference in New Issue
Block a user