Skip to content

Commit

Permalink
tabbed: eliminate double-free on error path
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Mar 25, 2024
1 parent 34b6cc1 commit adc7313
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/lib/tabbed.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,18 @@ nctabbed* nctabbed_create(ncplane* n, const nctabbed_options* topts){
nt->leftmost = nt->selected = NULL;
nt->tabcount = 0;
nt->sepcols = 0;
memcpy(&nt->opts, topts, sizeof(*topts));
nt->opts.separator = NULL;
nt->opts.selchan = topts->selchan;
nt->opts.hdrchan = topts->hdrchan;
nt->opts.sepchan = topts->sepchan;
nt->opts.flags = topts->flags;
if(topts->separator){
if((nt->opts.separator = strdup(topts->separator)) == NULL){
logerror("Couldn't allocate nctabbed separator");
if((nt->sepcols = ncstrwidth(topts->separator, NULL, NULL)) < 0){
logerror("Separator string contains illegal characters");
goto err;
}
if((nt->sepcols = ncstrwidth(nt->opts.separator, NULL, NULL)) < 0){
logerror("Separator string contains illegal characters");
free(nt->opts.separator);
if((nt->opts.separator = strdup(topts->separator)) == NULL){
logerror("Couldn't allocate nctabbed separator");
goto err;
}
}
Expand Down

0 comments on commit adc7313

Please sign in to comment.