Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

accounting: fix memory leak from stats groups on long-running rcd

nielashabae66ee1a0e
diff --git a/fs/accounting/stats.go b/fs/accounting/stats.go
index 8dc14f236..a1467b957 100644
--- a/fs/accounting/stats.go
+++ b/fs/accounting/stats.go
@@ -33,7 +33,6 @@ var MaxCompletedTransfers = 100
// to correctly count the updated fields
type StatsInfo struct {
mu sync.RWMutex
- ctx context.Context
ci *fs.ConfigInfo
bytes int64
errors int64
@@ -85,7 +84,6 @@ type averageValues struct {
func NewStats(ctx context.Context) *StatsInfo {
ci := fs.GetConfig(ctx)
s := &StatsInfo{
- ctx: ctx,
ci: ci,
checking: newTransferMap(ci.Checkers, "checking"),
transferring: newTransferMap(ci.Transfers, "transferring"),
@@ -518,10 +516,10 @@ func (s *StatsInfo) String() string {
// Add per transfer stats if required
if !s.ci.StatsOneLine {
if !s.checking.empty() {
- _, _ = fmt.Fprintf(buf, "Checking:\n%s\n", s.checking.String(s.ctx, s.inProgress, s.transferring))
+ _, _ = fmt.Fprintf(buf, "Checking:\n%s\n", s.checking.String(s.ci, s.inProgress, s.transferring))
}
if !s.transferring.empty() {
- _, _ = fmt.Fprintf(buf, "Transferring:\n%s\n", s.transferring.String(s.ctx, s.inProgress, nil))
+ _, _ = fmt.Fprintf(buf, "Transferring:\n%s\n", s.transferring.String(s.ci, s.inProgress, nil))
}
}
diff --git a/fs/accounting/transfermap.go b/fs/accounting/transfermap.go
index 1f8f6c752..8e05142b1 100644
--- a/fs/accounting/transfermap.go
+++ b/fs/accounting/transfermap.go
@@ -1,7 +1,6 @@
package accounting
import (
- "context"
"fmt"
"maps"
"sort"
@@ -91,10 +90,9 @@ func (tm *transferMap) _sortedSlice() []*Transfer {
// String returns string representation of map items excluding any in
// exclude (if set).
-func (tm *transferMap) String(ctx context.Context, progress *inProgress, exclude *transferMap) string {
+func (tm *transferMap) String(ci *fs.ConfigInfo, progress *inProgress, exclude *transferMap) string {
tm.mu.RLock()
defer tm.mu.RUnlock()
- ci := fs.GetConfig(ctx)
stringList := make([]string, 0, len(tm.items))
for _, tr := range tm._sortedSlice() {
var what = tr.what