forked from TrueCloudLab/rclone
cmount: fix openFile leak
This commit is contained in:
parent
0c055a1215
commit
bc88f1dafa
1 changed files with 20 additions and 6 deletions
|
@ -161,19 +161,28 @@ func (fsys *FS) lookupFile(path string) (file *mountlib.File, errc int) {
|
||||||
return file, 0
|
return file, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the underlying handle from the file handle
|
// Get the underlying openFile handle from the file handle
|
||||||
func (fsys *FS) getHandleFromFh(fh uint64) (handle mountlib.Noder, errc int) {
|
func (fsys *FS) getOpenFilesFromFh(fh uint64) (of *openFiles, errc int) {
|
||||||
switch {
|
switch {
|
||||||
case fsys.openFilesRd.InRange(fh):
|
case fsys.openFilesRd.InRange(fh):
|
||||||
return fsys.openFilesRd.Get(fh)
|
return fsys.openFilesRd, 0
|
||||||
case fsys.openFilesWr.InRange(fh):
|
case fsys.openFilesWr.InRange(fh):
|
||||||
return fsys.openFilesWr.Get(fh)
|
return fsys.openFilesWr, 0
|
||||||
case fsys.openDirs.InRange(fh):
|
case fsys.openDirs.InRange(fh):
|
||||||
return fsys.openDirs.Get(fh)
|
return fsys.openDirs, 0
|
||||||
}
|
}
|
||||||
return nil, -fuse.EBADF
|
return nil, -fuse.EBADF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the underlying handle from the file handle
|
||||||
|
func (fsys *FS) getHandleFromFh(fh uint64) (handle mountlib.Noder, errc int) {
|
||||||
|
of, errc := fsys.getOpenFilesFromFh(fh)
|
||||||
|
if errc != 0 {
|
||||||
|
return nil, errc
|
||||||
|
}
|
||||||
|
return of.Get(fh)
|
||||||
|
}
|
||||||
|
|
||||||
// get a node from the path or from the fh if not fhUnset
|
// get a node from the path or from the fh if not fhUnset
|
||||||
func (fsys *FS) getNode(path string, fh uint64) (node mountlib.Node, errc int) {
|
func (fsys *FS) getNode(path string, fh uint64) (node mountlib.Node, errc int) {
|
||||||
if fh == fhUnset {
|
if fh == fhUnset {
|
||||||
|
@ -462,10 +471,15 @@ func (fsys *FS) Flush(path string, fh uint64) (errc int) {
|
||||||
// Release closes the file if still open
|
// Release closes the file if still open
|
||||||
func (fsys *FS) Release(path string, fh uint64) (errc int) {
|
func (fsys *FS) Release(path string, fh uint64) (errc int) {
|
||||||
defer fs.Trace(path, "fh=0x%X", fh)("errc=%d", &errc)
|
defer fs.Trace(path, "fh=0x%X", fh)("errc=%d", &errc)
|
||||||
handle, errc := fsys.getHandleFromFh(fh)
|
of, errc := fsys.getOpenFilesFromFh(fh)
|
||||||
if errc != 0 {
|
if errc != 0 {
|
||||||
return errc
|
return errc
|
||||||
}
|
}
|
||||||
|
handle, errc := of.Get(fh)
|
||||||
|
if errc != 0 {
|
||||||
|
return errc
|
||||||
|
}
|
||||||
|
_ = of.Close(fh)
|
||||||
var err error
|
var err error
|
||||||
switch x := handle.(type) {
|
switch x := handle.(type) {
|
||||||
case *mountlib.ReadFileHandle:
|
case *mountlib.ReadFileHandle:
|
||||||
|
|
Loading…
Reference in a new issue