[bitmaps] kill memory leak on resize failure path

pull/2292/head
nick black 3 years ago
parent 5ce9f57540
commit 2c89553437
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -717,15 +717,20 @@ sprite_commit(tinfo* ti, fbuf* f, sprixel* s, unsigned forcescroll){
return 0;
}
static inline void
cleanup_tam(tament* tam, int ydim, int xdim){
for(int y = 0 ; y < ydim ; ++y){
for(int x = 0 ; x < xdim ; ++x){
free(tam[y * xdim + x].auxvector);
tam[y * xdim + x].auxvector = NULL;
}
}
}
static inline void
destroy_tam(ncplane* p){
if(p->tam){
for(int y = 0 ; y < p->leny ; ++y){
for(int x = 0 ; x < p->lenx ; ++x){
free(p->tam[y * p->lenx + x].auxvector);
p->tam[y * p->lenx + x].auxvector = NULL;
}
}
cleanup_tam(p->tam, p->leny, p->lenx);
free(p->tam);
}
}

@ -547,16 +547,6 @@ int kitty_commit(fbuf* f, sprixel* s, unsigned noscroll){
return 0;
}
static void
cleanup_tam(tament* tam, int ydim, int xdim){
for(int y = 0 ; y < ydim ; ++y){
for(int x = 0 ; x < xdim ; ++x){
free(tam[y * xdim + x].auxvector);
tam[y * xdim + x].auxvector = NULL;
}
}
}
static inline void*
zctx_origbuf(z_stream* zctx, int pixy, int pixx){
size_t blen = pixx * pixy * 4;

@ -1125,6 +1125,12 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
//fprintf(stderr, "ABOUT TO RESIZE: yoff/xoff: %d/%d\n", placey, placex);
// FIXME might need shrink down the TAM and kill unnecessary auxvecs
if(ncplane_resize(n, 0, 0, s->dimy, s->dimx, placey, placex, s->dimy, s->dimx)){
// if we blow up here, then we've got a TAM sized to the sprixel, rather
// than the plane. running it through destroy_tam() via ncplane_destroy()
// will use incorrect bounds for scrubbing said TAM. do it manually here.
cleanup_tam(n->tam, rows, cols);
free(n->tam);
n->tam = NULL;
sprixel_hide(bargs.u.pixel.spx);
ncplane_destroy(createdn);
return NULL;

Loading…
Cancel
Save