From 78269365b43eba75f886d2e45bfb599eaadd76a0 Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 14 Dec 2021 01:30:34 -0500 Subject: [PATCH] ncplane_resize_internal: realloc only when keepleny && !keepy #2426 --- src/lib/notcurses.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index cb3e5083c..91ed59686 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -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)); }