diff --git a/src/lib/fbuf.h b/src/lib/fbuf.h index 672f95275..d004f8484 100644 --- a/src/lib/fbuf.h +++ b/src/lib/fbuf.h @@ -155,6 +155,14 @@ fbuf_reset(fbuf* f){ f->used = 0; } +static inline int +fbuf_reserve(fbuf* f, size_t len){ + if(fbuf_grow(f, len)){ + return -1; + } + return 0; +} + static inline int fbuf_putc(fbuf* f, char c){ if(fbuf_grow(f, 1)){ diff --git a/src/lib/linux.c b/src/lib/linux.c index ec2ff71c7..140431d85 100644 --- a/src/lib/linux.c +++ b/src/lib/linux.c @@ -39,8 +39,7 @@ int fbcon_blit(struct ncplane* n, int linesize, const void* data, int cdimy = s->cellpxy; // FIXME this will need be a copy of the tinfo's fbuf map size_t flen = leny * lenx * 4; - s->glyph.buf = malloc(flen); - if(s->glyph.buf == NULL){ + if(fbuf_reserve(&s->glyph, flen)){ return -1; } tament* tam = NULL; @@ -114,7 +113,7 @@ error: if(!reuse){ free(tam); } - free(s->glyph.buf); + fbuf_free(&s->glyph); s->glyph.size = 0; return -1; }