diff --git a/stbridge/saf.go b/stbridge/saf.go index b7bbc76..474363d 100644 --- a/stbridge/saf.go +++ b/stbridge/saf.go @@ -617,7 +617,7 @@ func (sn *safNode) getChildren(opts *safOpts, allowFiles bool) (map[string]*safN sn.updateChildrenLocked(opts, children, expiry.Unix()) - return children, nil + return maps.Clone(children), nil } // Get the child node referenced by the specified relative path. ".." components diff --git a/stbridge/saf_test.go b/stbridge/saf_test.go index 2572aca..5c1d576 100644 --- a/stbridge/saf_test.go +++ b/stbridge/saf_test.go @@ -11,6 +11,7 @@ import ( "maps" "os" "path/filepath" + "reflect" "slices" "strconv" "syscall" @@ -317,6 +318,9 @@ func TestGetChildren(t *testing.T) { if calls != 1 { t.Errorf("queryChildDocumentsJson was not called when expired") } + if reflect.ValueOf(children).Pointer() == reflect.ValueOf(node.children).Pointer() { + t.Errorf("children was not a copy: %p (%+v)", children, children) + } if len(children) != 2 { t.Errorf("invalid number of children") } @@ -341,6 +345,9 @@ func TestGetChildren(t *testing.T) { if calls != 1 { t.Errorf("queryChildDocumentsJson was called when not expired") } + if reflect.ValueOf(children).Pointer() == reflect.ValueOf(node.children).Pointer() { + t.Errorf("children was not a copy: %p (%+v)", children, children) + } if !maps.Equal(children, oldChildren) { t.Errorf("children changed: %+v != %+v", children, oldChildren) }