Here, I: 1) remove a useless comment 2) remove a needless void* cast 3) remove a bunch of NULL-checks for free() 4) simplify a little associated logic
Call me a one trick pony. ok? Index: cmdbuf.c =================================================================== RCS file: /cvs/src/usr.bin/less/cmdbuf.c,v retrieving revision 1.11 diff -u -p -r1.11 cmdbuf.c --- cmdbuf.c 9 Nov 2015 04:10:57 -0000 1.11 +++ cmdbuf.c 9 Nov 2015 04:38:23 -0000 @@ -918,13 +918,8 @@ init_compl(void) char *word; char c; - /* - * Get rid of any previous tk_text. - */ - if (tk_text != NULL) { - free(tk_text); - tk_text = NULL; - } + free(tk_text); + tk_text = NULL; /* * Find the original (uncompleted) word in the command buffer. */ @@ -939,8 +934,7 @@ init_compl(void) /* * Save the original (uncompleted) word */ - if (tk_original != NULL) - free(tk_original); + free(tk_original); tk_original = ecalloc(cp-word+1, sizeof (char)); (void) strncpy(tk_original, word, cp-word); /* @@ -954,12 +948,11 @@ init_compl(void) tk_text = fcomplete(word); } else { char *qword = shell_quote(word+1); - if (qword == NULL) { + if (qword == NULL) tk_text = fcomplete(word+1); - } else { + else tk_text = fcomplete(qword); - free(qword); - } + free(qword); } *cp = c; } Index: command.c =================================================================== RCS file: /cvs/src/usr.bin/less/command.c,v retrieving revision 1.22 diff -u -p -r1.22 command.c --- command.c 7 Nov 2015 18:07:44 -0000 1.22 +++ command.c 9 Nov 2015 04:38:23 -0000 @@ -198,8 +198,7 @@ exec_mca(void) */ while (*cbuf == '+' || *cbuf == ' ') cbuf++; - if (every_first_cmd != NULL) - free(every_first_cmd); + free(every_first_cmd); if (*cbuf == '\0') every_first_cmd = NULL; else Index: line.c =================================================================== RCS file: /cvs/src/usr.bin/less/line.c,v retrieving revision 1.14 diff -u -p -r1.14 line.c --- line.c 6 Nov 2015 15:50:33 -0000 1.14 +++ line.c 9 Nov 2015 04:38:23 -0000 @@ -98,10 +98,8 @@ expand_linebuf(void) char *new_buf = realloc(linebuf, new_size); char *new_attr = realloc(attr, new_size); if (new_buf == NULL || new_attr == NULL) { - if (new_attr != NULL) - free(new_attr); - if (new_buf != NULL) - free(new_buf); + free(new_attr); + free(new_buf); return (1); } linebuf = new_buf; Index: option.c =================================================================== RCS file: /cvs/src/usr.bin/less/option.c,v retrieving revision 1.12 diff -u -p -r1.12 option.c --- option.c 7 Nov 2015 18:07:44 -0000 1.12 +++ option.c 9 Nov 2015 04:38:23 -0000 @@ -307,8 +307,7 @@ scan_option(char *s) */ if (o->ofunc != NULL) (*o->ofunc)(INIT, str); - if (str != NULL) - free(str); + free(str); } } Index: search.c =================================================================== RCS file: /cvs/src/usr.bin/less/search.c,v retrieving revision 1.11 diff -u -p -r1.11 search.c --- search.c 6 Nov 2015 15:50:33 -0000 1.11 +++ search.c 9 Nov 2015 04:38:23 -0000 @@ -97,12 +97,10 @@ set_pattern(struct pattern_info *info, c else if (compile_pattern(pattern, search_type, &info->compiled) < 0) return (-1); /* Pattern compiled successfully; save the text too. */ - if (info->text != NULL) - free(info->text); + free(info->text); info->text = NULL; - if (pattern != NULL) { + if (pattern != NULL) info->text = estrdup(pattern); - } info->search_type = search_type; /* @@ -291,7 +289,7 @@ clr_hlist(struct hilite *anchor) for (hl = anchor->hl_first; hl != NULL; hl = nexthl) { nexthl = hl->hl_next; - free((void*)hl); + free(hl); } anchor->hl_first = NULL; prep_startpos = prep_endpos = -1;