fix: fix thread synchronization issue #6245 (#7800)

This commit is contained in:
Jens Reimann 2021-10-25 00:10:21 +02:00 committed by GitHub
parent 6b9865c607
commit 880ea6dba8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -63,6 +63,9 @@ const (
// Writer is the interface to render a template
type Writer interface {
// Write renders the template.
// NOTE: Implementors must ensure that the content of the returned slice is not modified by the implementation
// after the return of this function.
Write(conf config.TemplateConfig) ([]byte, error)
}
@ -202,7 +205,12 @@ func (t *Template) Write(conf config.TemplateConfig) ([]byte, error) {
return nil, err
}
return outCmdBuf.Bytes(), nil
// make a copy to ensure that we are no longer modifying the content of the buffer
out := outCmdBuf.Bytes()
res := make([]byte, len(out))
copy(res, out)
return res, nil
}
var (