diff --git a/zapcore/console_encoder.go b/zapcore/console_encoder.go index 54aae7ef9..6c6080366 100644 --- a/zapcore/console_encoder.go +++ b/zapcore/console_encoder.go @@ -130,7 +130,12 @@ func (c consoleEncoder) EncodeEntry(ent Entry, fields []Field) (*buffer.Buffer, func (c consoleEncoder) writeContext(line *buffer.Buffer, extra []Field) { context := c.jsonEncoder.Clone().(*jsonEncoder) - defer context.buf.Free() + defer func() { + // putJSONEncoder assumes the buffer is still used, but we write out the buffer so + // we can free it. + context.buf.Free() + putJSONEncoder(context) + }() addFields(context, extra) context.closeOpenNamespaces()