Skip to content

Commit

Permalink
local: try to eliminate hash memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal-Leszczynski committed Nov 23, 2023
1 parent 5ef09c5 commit b76ed0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 9 additions & 2 deletions backend/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,9 @@ func (f *Fs) Purge(ctx context.Context, dir string) error {

// Move src to this remote using server-side move operations.
//
// This is stored with the remote path given
// # This is stored with the remote path given
//
// It returns the destination Object and a possible error
// # It returns the destination Object and a possible error
//
// Will only be called if src.Fs().Name() == f.Name()
//
Expand Down Expand Up @@ -898,6 +898,13 @@ func (o *Object) Hash(ctx context.Context, r hash.Type) (string, error) {
return hashValue, nil
}

// ClearHashes clears all types of calculated hashes.
func (o *Object) ClearHashes() {
o.fs.objectMetaMu.RLock()
defer o.fs.objectMetaMu.RUnlock()
o.hashes = nil
}

// Size returns the size of an object in bytes
func (o *Object) Size() int64 {
o.fs.objectMetaMu.RLock()
Expand Down
5 changes: 5 additions & 0 deletions fs/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/pkg/errors"
"github.com/rclone/rclone/backend/local"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/accounting"
"github.com/rclone/rclone/fs/filter"
Expand Down Expand Up @@ -408,6 +409,10 @@ func (s *syncCopyMove) pairCopyOrMove(ctx context.Context, in *pipe, fdst fs.Fs,
} else {
_, err = operations.Copy(ctx, fdst, pair.Dst, name, src)
}
// TODO: try to eliminate memory hash memory leak
if o, ok := src.(*local.Object); ok {
o.ClearHashes()
}
s.processError(err)
}
}
Expand Down

0 comments on commit b76ed0b

Please sign in to comment.