Mutex protect buffer access in standard renderer

This commit is contained in:
Christian Muehlhaeuser 2021-03-13 04:27:16 +01:00
parent ac28669943
commit a72db29ae0
1 changed files with 3 additions and 3 deletions

View File

@ -88,6 +88,9 @@ func (r *standardRenderer) listen() {
// flush renders the buffer. // flush renders the buffer.
func (r *standardRenderer) flush() { func (r *standardRenderer) flush() {
r.mtx.Lock()
defer r.mtx.Unlock()
if r.buf.Len() == 0 || r.buf.String() == r.lastRender { if r.buf.Len() == 0 || r.buf.String() == r.lastRender {
// Nothing to do // Nothing to do
return return
@ -95,9 +98,6 @@ func (r *standardRenderer) flush() {
out := new(bytes.Buffer) out := new(bytes.Buffer)
r.mtx.Lock()
defer r.mtx.Unlock()
// Clear any lines we painted in the last render. // Clear any lines we painted in the last render.
if r.linesRendered > 0 { if r.linesRendered > 0 {
for i := r.linesRendered - 1; i > 0; i-- { for i := r.linesRendered - 1; i > 0; i-- {