From a72db29ae052f3c8a6d8085be2dccf663aca8584 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sat, 13 Mar 2021 04:27:16 +0100 Subject: [PATCH] Mutex protect buffer access in standard renderer --- standard_renderer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/standard_renderer.go b/standard_renderer.go index 5fb48e8..4a4079a 100644 --- a/standard_renderer.go +++ b/standard_renderer.go @@ -88,6 +88,9 @@ func (r *standardRenderer) listen() { // flush renders the buffer. func (r *standardRenderer) flush() { + r.mtx.Lock() + defer r.mtx.Unlock() + if r.buf.Len() == 0 || r.buf.String() == r.lastRender { // Nothing to do return @@ -95,9 +98,6 @@ func (r *standardRenderer) flush() { out := new(bytes.Buffer) - r.mtx.Lock() - defer r.mtx.Unlock() - // Clear any lines we painted in the last render. if r.linesRendered > 0 { for i := r.linesRendered - 1; i > 0; i-- {