From a0d61dc2c7439bdea7e1a9920713b1134367be58 Mon Sep 17 00:00:00 2001 From: Marc Brooks Date: Mon, 12 Jan 2026 16:51:46 -0600 Subject: [PATCH] fix: return dict to Event pool (#749) Return dict to event pool in Array.Dict() --- README.md | 2 +- array.go | 1 + event.go | 7 +++---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6659e2d..f7caa1c 100644 --- a/README.md +++ b/README.md @@ -827,4 +827,4 @@ references to them from within any `MarshalZerologArray(a *Array)` callback (e.g own code as they will be cleared and returned to the pool after being buffered by a call to `Context.Array()` or `Event.Array()`. Any _dictionary_ `Event` returned from `Context.CreateDict()` or `Event.CreateDict()` **must not** be referenced after being -buffered by a call to `Context.Dict()` or `Event.Dict()` as they will be cleared and returned to the pool. +buffered by a call to `Array.Dict()`, `Context.Dict()`, or `Event.Dict()` as they will be cleared and returned to the pool. diff --git a/array.go b/array.go index a75a572..dbb0bda 100644 --- a/array.go +++ b/array.go @@ -265,6 +265,7 @@ func (a *Array) MACAddr(ha net.HardwareAddr) *Array { func (a *Array) Dict(dict *Event) *Array { dict.buf = enc.AppendEndMarker(dict.buf) a.buf = append(enc.AppendArrayDelim(a.buf), dict.buf...) + putEvent(dict) return a } diff --git a/event.go b/event.go index 0e05347..82d771f 100644 --- a/event.go +++ b/event.go @@ -180,11 +180,10 @@ func (e *Event) Fields(fields interface{}) *Event { // Dict adds the field key with a dict to the event context. // Use e.CreateDict() to create the dictionary. func (e *Event) Dict(key string, dict *Event) *Event { - if e == nil { - return e + if e != nil { + dict.buf = enc.AppendEndMarker(dict.buf) + e.buf = append(enc.AppendKey(e.buf, key), dict.buf...) } - dict.buf = enc.AppendEndMarker(dict.buf) - e.buf = append(enc.AppendKey(e.buf, key), dict.buf...) putEvent(dict) return e }