nctree_create(): free plane on all error paths #1164

pull/1351/head
nick black 4 years ago committed by Nick Black
parent 74079c4b65
commit 293618e427

@ -98,22 +98,29 @@ nctree_inner_create(ncplane* n, const struct nctree_options* opts){
return ret; return ret;
} }
// FIXME free up |n| on all error paths
nctree* nctree_create(ncplane* n, const struct nctree_options* opts){ nctree* nctree_create(ncplane* n, const struct nctree_options* opts){
notcurses* nc = ncplane_notcurses(n); notcurses* nc = ncplane_notcurses(n);
if(opts->flags){ if(opts->flags){
logwarn(nc, "Passed invalid flags 0x%016jx\n", (uint64_t)opts->flags); logwarn(nc, "Passed invalid flags 0x%016jx\n", (uint64_t)opts->flags);
return NULL; goto error;
} }
if(opts->count == 0 || opts->items == NULL){ if(opts->count == 0 || opts->items == NULL){
logerror(nc, "Can't create empty tree\n"); logerror(nc, "Can't create empty tree\n");
return NULL; goto error;
} }
if(opts->nctreecb == NULL){ if(opts->nctreecb == NULL){
logerror(nc, "Can't use NULL callback\n"); logerror(nc, "Can't use NULL callback\n");
return NULL; goto error;
}
nctree* ret = nctree_inner_create(n, opts);
if(ret == NULL){
goto error;
} }
return nctree_inner_create(n, opts); return ret;
error:
ncplane_destroy(n);
return NULL;
} }
void nctree_destroy(nctree* n){ void nctree_destroy(nctree* n){

Loading…
Cancel
Save