Skip to content

Commit a0d61dc

Browse files
authored
fix: return dict to Event pool (#749)
Return dict to event pool in Array.Dict()
1 parent f6fbd33 commit a0d61dc

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,4 +827,4 @@ references to them from within any `MarshalZerologArray(a *Array)` callback (e.g
827827
own code as they will be cleared and returned to the pool after being buffered by a call to `Context.Array()` or `Event.Array()`.
828828

829829
Any _dictionary_ `Event` returned from `Context.CreateDict()` or `Event.CreateDict()` **must not** be referenced after being
830-
buffered by a call to `Context.Dict()` or `Event.Dict()` as they will be cleared and returned to the pool.
830+
buffered by a call to `Array.Dict()`, `Context.Dict()`, or `Event.Dict()` as they will be cleared and returned to the pool.

array.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ func (a *Array) MACAddr(ha net.HardwareAddr) *Array {
265265
func (a *Array) Dict(dict *Event) *Array {
266266
dict.buf = enc.AppendEndMarker(dict.buf)
267267
a.buf = append(enc.AppendArrayDelim(a.buf), dict.buf...)
268+
putEvent(dict)
268269
return a
269270
}
270271

event.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,10 @@ func (e *Event) Fields(fields interface{}) *Event {
180180
// Dict adds the field key with a dict to the event context.
181181
// Use e.CreateDict() to create the dictionary.
182182
func (e *Event) Dict(key string, dict *Event) *Event {
183-
if e == nil {
184-
return e
183+
if e != nil {
184+
dict.buf = enc.AppendEndMarker(dict.buf)
185+
e.buf = append(enc.AppendKey(e.buf, key), dict.buf...)
185186
}
186-
dict.buf = enc.AppendEndMarker(dict.buf)
187-
e.buf = append(enc.AppendKey(e.buf, key), dict.buf...)
188187
putEvent(dict)
189188
return e
190189
}

0 commit comments

Comments
 (0)