1
0
mirror of https://github.com/rs/zerolog synced 2026-06-08 17:13:30 +00:00

fix: return dict to Event pool (#749)

Return dict to event pool in Array.Dict()
This commit is contained in:
Marc Brooks
2026-01-12 16:51:46 -06:00
committed by GitHub
parent f6fbd330be
commit a0d61dc2c7
3 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -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.
+1
View File
@@ -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
}
+3 -4
View File
@@ -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
}