log: clone terminal handler attrs (#35141)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

Clone the existing terminal handler attrs before appending new attrs.
This avoids a potential attr memory overwrite when append reuses the
backing array shared with the parent handler.
This commit is contained in:
cui 2026-06-30 21:12:47 +08:00 committed by GitHub
parent 32986bf084
commit 409aaefac1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,7 @@ import (
"log/slog" "log/slog"
"math/big" "math/big"
"reflect" "reflect"
"slices"
"sync" "sync"
"time" "time"
@ -97,7 +98,7 @@ func (h *TerminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
wr: h.wr, wr: h.wr,
lvl: h.lvl, lvl: h.lvl,
useColor: h.useColor, useColor: h.useColor,
attrs: append(h.attrs, attrs...), attrs: append(slices.Clone(h.attrs), attrs...),
fieldPadding: make(map[string]int), fieldPadding: make(map[string]int),
} }
} }