ncplane_resize_internal: realloc only when keepleny && !keepy #2426

This commit is contained in:
nick black 2021-12-14 01:30:34 -05:00
parent 7a99d00719
commit 78269365b4
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

View File

@ -858,13 +858,13 @@ int ncplane_resize_internal(ncplane* n, int keepy, int keepx,
// we might realloc instead of mallocing, in which case we NULL out
// |preserved|. it must otherwise be free()d at the end.
nccell* preserved = n->fb;
if(cols == xlen && cols == keeplenx && keepy){
if(cols == xlen && cols == keeplenx && keepleny && !keepy){
// we need release the cells that we're losing, lest we leak EGCpool
// memory. unfortunately, this means we mutate the plane on the error case.
// any solution would involve copying them out first. we only do this if
// we're keeping some, as we otherwise drop the EGCpool in toto.
if(keptarea && n->leny > ylen){
for(unsigned y = ylen ; y < n->leny ; ++y){
if(n->leny > keepleny){
for(unsigned y = keepleny ; y < n->leny ; ++y){
for(unsigned x = 0 ; x < n->lenx ; ++x){
nccell_release(n, ncplane_cell_ref_yx(n, y, x));
}