From ce893cb6dbe35f476e0a58f5716bcb0f8e1e0c49 Mon Sep 17 00:00:00 2001 From: Weixie Cui Date: Thu, 11 Jun 2026 00:32:12 +0800 Subject: [PATCH] log: clone terminal handler attrs 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. --- log/handler.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/log/handler.go b/log/handler.go index 9c98552e7c..201d15218a 100644 --- a/log/handler.go +++ b/log/handler.go @@ -7,6 +7,7 @@ import ( "log/slog" "math/big" "reflect" + "slices" "sync" "time" @@ -95,7 +96,7 @@ func (h *TerminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler { wr: h.wr, lvl: h.lvl, useColor: h.useColor, - attrs: append(h.attrs, attrs...), + attrs: append(slices.Clone(h.attrs), attrs...), fieldPadding: make(map[string]int), } }