From e9f4a2c4b548b2e6c6efb209868c6715ed98e826 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Wed, 21 Oct 2020 17:04:48 -0700 Subject: [PATCH] remove unnecessary guards on calls to free() Freeing NULL is a no-op, so there is no need for these extra conditionals. --- cmd/gvmap/gvmap.c | 2 +- cmd/lefty/common.c | 9 +++------ cmd/lefty/txtview.c | 18 ++++++------------ cmd/tools/bcomps.c | 3 +-- cmd/tools/graphml2gv.c | 3 +-- cmd/tools/gv2gxl.c | 3 +-- cmd/tools/gvpack.c | 2 +- cmd/tools/gxl2gv.c | 3 +-- lib/ast/pathpath.c | 3 +-- lib/common/emit.c | 20 +++++++------------- lib/common/htmlparse.y | 3 +-- lib/common/htmltable.c | 6 ++---- lib/common/input.c | 2 +- lib/common/labels.c | 2 +- lib/common/psusershape.c | 3 +-- lib/common/shapes.c | 2 +- lib/common/textspan.c | 4 ++-- lib/common/types.h | 2 +- lib/common/utils.c | 2 +- lib/dotgen/aspect.c | 3 +-- lib/dotgen/dotinit.c | 4 ++-- lib/fdpgen/layout.c | 3 +-- lib/glcomp/glcompfont.c | 3 +-- lib/glcomp/glcomplabel.c | 3 +-- lib/glcomp/glcomptext.c | 6 ++---- lib/glcomp/glcomptexture.c | 9 +++------ lib/glcomp/glutils.c | 3 +-- lib/gvc/gvconfig.c | 3 +-- lib/gvc/gvcontext.c | 6 ++---- lib/gvc/gvevent.c | 12 ++++-------- lib/gvc/gvjobs.c | 12 ++++-------- lib/neatogen/adjust.c | 2 +- lib/neatogen/delaunay.c | 18 ++++++------------ lib/neatogen/dijkstra.c | 2 +- lib/neatogen/lu.c | 6 ++---- lib/neatogen/neatoinit.c | 3 +-- lib/ortho/ortho.c | 2 +- lib/osage/osageinit.c | 4 +--- lib/pathplan/cvt.c | 6 ++---- lib/sfdpgen/PriorityQueue.c | 4 +--- lib/sfio/sfclose.c | 9 +++------ lib/sfio/sfmode.c | 6 ++---- lib/sfio/sfvprintf.c | 9 +++------ lib/sfio/sfvscanf.c | 9 +++------ plugin/gd/gvrender_gd.c | 3 +-- tclpkg/tclpathplan/tclpathplan.c | 3 +-- 46 files changed, 86 insertions(+), 159 deletions(-) diff --git a/cmd/gvmap/gvmap.c b/cmd/gvmap/gvmap.c index 8de13a610..9599b26af 100644 --- a/cmd/gvmap/gvmap.c +++ b/cmd/gvmap/gvmap.c @@ -382,7 +382,7 @@ init(int argc, char **argv, params_t* pm) } break; case 'l': - if (pm->plot_label) free (pm->plot_label); + free (pm->plot_label); pm->plot_label = strdup (optarg); break; case ':': diff --git a/cmd/lefty/common.c b/cmd/lefty/common.c index 9a3796914..9deae88aa 100644 --- a/cmd/lefty/common.c +++ b/cmd/lefty/common.c @@ -147,12 +147,9 @@ int init (char *aout) { } void term (void) { - if (lpathp) - free (lpathp); - if (pathp) - free (pathp); - if (cmdp) - free (cmdp); + free (lpathp); + free (pathp); + free (cmdp); } /* given a file name, it looks for this file in LEFTYPATH diff --git a/cmd/lefty/txtview.c b/cmd/lefty/txtview.c index 974c1c283..f3a4999e2 100644 --- a/cmd/lefty/txtview.c +++ b/cmd/lefty/txtview.c @@ -531,18 +531,15 @@ static void fillnode (txtnode_t *pnode, txtnode_t *cnode) { static void unfillnode (txtnode_t *cnode) { int i; - if (cnode->path) - free (cnode->path), cnode->path = NULL; + free (cnode->path), cnode->path = NULL; switch (cnode->mode) { case TXT_SEEN: - if (cnode->u.s.text) - free (cnode->u.s.text); + free (cnode->u.s.text); if (cnode->u.s.wi) Gdestroywidget (cnode->u.s.wi); break; case TXT_ABSTRACT: - if (cnode->u.a.text) - free (cnode->u.a.text); + free (cnode->u.a.text); if (cnode->u.a.wi) Gdestroywidget (cnode->u.a.wi); break; @@ -550,18 +547,15 @@ static void unfillnode (txtnode_t *cnode) { if (cnode->ttype == T_TABLE) { for (i = 0; i < cnode->u.f.t.n; i++) unfillnode (&cnode->u.f.t.list[i]); - if (cnode->u.f.t.list) - free (cnode->u.f.t.list); - if (cnode->u.f.t.ftext) - free (cnode->u.f.t.ftext); + free (cnode->u.f.t.list); + free (cnode->u.f.t.ftext); if (cnode->u.f.t.fwi) { Gdestroywidget (cnode->u.f.t.fwi); Gdestroywidget (cnode->u.f.t.mwi); Gdestroywidget (cnode->u.f.t.lwi); } } else { - if (cnode->u.f.s.text) - free (cnode->u.f.s.text); + free (cnode->u.f.s.text); if (cnode->u.f.s.wi) Gdestroywidget (cnode->u.f.s.wi); } diff --git a/cmd/tools/bcomps.c b/cmd/tools/bcomps.c index 584c57fc5..acd4a5641 100644 --- a/cmd/tools/bcomps.c +++ b/cmd/tools/bcomps.c @@ -95,8 +95,7 @@ static char *blockName(char *gname, int d) sz = strlen(gname) + 128; if (sz > bufsz) { - if (buf) - free(buf); + free(buf); buf = malloc(sz); } diff --git a/cmd/tools/graphml2gv.c b/cmd/tools/graphml2gv.c index da32439c1..061bd45a8 100644 --- a/cmd/tools/graphml2gv.c +++ b/cmd/tools/graphml2gv.c @@ -586,8 +586,7 @@ static void endElementHandler(void *userData, const char *name) setGraphAttr(G, name, value, ud); break; } - if (dynbuf) - free(dynbuf); + free(dynbuf); ud->globalAttrType = TAG_NONE; } } diff --git a/cmd/tools/gv2gxl.c b/cmd/tools/gv2gxl.c index 1e0b600d3..58ed04021 100644 --- a/cmd/tools/gv2gxl.c +++ b/cmd/tools/gv2gxl.c @@ -524,8 +524,7 @@ writeHdr(gxlstate_t * stp, Agraph_t * g, FILE * gxlFile, int top) tabover(gxlFile); fprintf(gxlFile, "\n", bp); - if (dynbuf) - free(dynbuf); + free(dynbuf); Level++; } else { Tailport = agattr(g, AGEDGE, "tailport", NIL(char *)); diff --git a/cmd/tools/gvpack.c b/cmd/tools/gvpack.c index 42f25eae2..43cce0ff8 100644 --- a/cmd/tools/gvpack.c +++ b/cmd/tools/gvpack.c @@ -558,7 +558,7 @@ static char *xName(Dt_t * names, char *oldname) p->cnt++; len = strlen(oldname) + 100; /* 100 for "_gv" and decimal no. */ if (namelen < len) { - if (name) free (name); + free (name); name = N_NEW(len, char); namelen = len; } diff --git a/cmd/tools/gxl2gv.c b/cmd/tools/gxl2gv.c index c34adfc63..9ceef4b34 100644 --- a/cmd/tools/gxl2gv.c +++ b/cmd/tools/gxl2gv.c @@ -628,8 +628,7 @@ static void endElementHandler(void *userData, const char *name) setGraphAttr(G, name, value, ud); break; } - if (dynbuf) - free(dynbuf); + free(dynbuf); ud->globalAttrType = TAG_NONE; } else if (strcmp(name, "string") == 0 || strcmp(name, "bool") == 0 diff --git a/lib/ast/pathpath.c b/lib/ast/pathpath.c index 2e8312564..bddb9e6be 100644 --- a/lib/ast/pathpath.c +++ b/lib/ast/pathpath.c @@ -46,8 +46,7 @@ char *pathpath(char *path, const char *p, const char *a, int mode) if (!path) path = buf; if (!p) { - if (cmd) - free(cmd); + free(cmd); cmd = a ? strdup(a) : (char *) 0; return 0; } diff --git a/lib/common/emit.c b/lib/common/emit.c index b9b333316..97914b99a 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -1194,18 +1194,12 @@ static void init_layering(GVC_t * gvc, graph_t * g) char *str; /* free layer strings and pointers from previous graph */ - if (gvc->layers) { - free(gvc->layers); - gvc->layers = NULL; - } - if (gvc->layerIDs) { - free(gvc->layerIDs); - gvc->layerIDs = NULL; - } - if (gvc->layerlist) { - free(gvc->layerlist); - gvc->layerlist = NULL; - } + free(gvc->layers); + gvc->layers = NULL; + free(gvc->layerIDs); + gvc->layerIDs = NULL; + free(gvc->layerlist); + gvc->layerlist = NULL; if ((str = agget(g, "layers")) != 0) { gvc->numLayers = parse_layers(gvc, g, str); if (((str = agget(g, "layerselect")) != 0) && *str) { @@ -2745,7 +2739,7 @@ emit_edge_label(GVJ_t* job, textlabel_t* lbl, emit_state_t lkind, int explicit, } gvrender_end_anchor(job); } - if (newid) free (newid); + free (newid); job->obj->emit_state = old_emit_state; } diff --git a/lib/common/htmlparse.y b/lib/common/htmlparse.y index e8b3fee49..e34dd8d15 100644 --- a/lib/common/htmlparse.y +++ b/lib/common/htmlparse.y @@ -132,8 +132,7 @@ typedef struct { static void free_fitem(Dt_t* d, fitem* p, Dtdisc_t* ds) { - if (p->ti.str) - free (p->ti.str); + free (p->ti.str); free (p); } diff --git a/lib/common/htmltable.c b/lib/common/htmltable.c index a01fd8bf1..b4758d39a 100644 --- a/lib/common/htmltable.c +++ b/lib/common/htmltable.c @@ -813,16 +813,14 @@ void free_html_text(htmltxt_t * t) for (i = 0; i < t->nspans; i++) { ti = tl->items; for (j = 0; j < tl->nitems; j++) { - if (ti->str) - free(ti->str); + free(ti->str); if (ti->layout && ti->free_layout) ti->free_layout(ti->layout); ti++; } tl++; } - if (t->spans) - free(t->spans); + free(t->spans); free(t); } diff --git a/lib/common/input.c b/lib/common/input.c index 003268f02..4c0536db9 100644 --- a/lib/common/input.c +++ b/lib/common/input.c @@ -881,7 +881,7 @@ void graph_cleanup(graph_t *g) { if (GD_drawing(g) && GD_drawing(g)->xdots) freeXDot ((xdot*)GD_drawing(g)->xdots); - if (GD_drawing(g) && GD_drawing(g)->id) + if (GD_drawing(g)) free (GD_drawing(g)->id); free(GD_drawing(g)); GD_drawing(g) = NULL; diff --git a/lib/common/labels.c b/lib/common/labels.c index 7339590b0..61aca92ed 100644 --- a/lib/common/labels.c +++ b/lib/common/labels.c @@ -197,7 +197,7 @@ void free_textspan(textspan_t * tl, int cnt) if (!tl) return; for (i = 0; i < cnt; i++) { - if ((i == 0) && tlp->str) + if (i == 0) free(tlp->str); if (tlp->layout && tlp->free_layout) tlp->free_layout (tlp->layout); diff --git a/lib/common/psusershape.c b/lib/common/psusershape.c index 6be0f84a3..515ffc42e 100644 --- a/lib/common/psusershape.c +++ b/lib/common/psusershape.c @@ -122,8 +122,7 @@ void epsf_init(node_t * n) void epsf_free(node_t * n) { - if (ND_shape_info(n)) - free(ND_shape_info(n)); + free(ND_shape_info(n)); } diff --git a/lib/common/shapes.c b/lib/common/shapes.c index de7a898e9..6641a6ca0 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -3789,7 +3789,7 @@ static void record_gencode(GVJ_t * job, node_t * n) gen_fields(job, n, f); - if (clrs[0]) free (clrs[0]); + free (clrs[0]); if (doMap) { if (job->flags & EMIT_CLUSTERS_LAST) diff --git a/lib/common/textspan.c b/lib/common/textspan.c index 8038eaa03..bd57c4018 100644 --- a/lib/common/textspan.c +++ b/lib/common/textspan.c @@ -248,8 +248,8 @@ static void textfont_freef(Dt_t* dt, void* obj, Dtdisc_t* disc) { textfont_t *f = (textfont_t*)obj; - if (f->name) free(f->name); - if (f->color) free(f->color); + free(f->name); + free(f->color); free(f); } diff --git a/lib/common/types.h b/lib/common/types.h index 244408432..74dc0d5f0 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -271,7 +271,7 @@ extern "C" { #define elist_fastapp(item,L) do {L.list[L.size++] = item; L.list[L.size] = NULL;} while(0) #define elist_append(item,L) do {L.list = ALLOC(L.size + 2,L.list,edge_t*); L.list[L.size++] = item; L.list[L.size] = NULL;} while(0) #define alloc_elist(n,L) do {L.size = 0; L.list = N_NEW(n + 1,edge_t*); } while (0) -#define free_list(L) do {if (L.list) free(L.list);} while (0) +#define free_list(L) free(L.list) typedef enum {NATIVEFONTS,PSFONTS,SVGFONTS} fontname_kind; diff --git a/lib/common/utils.c b/lib/common/utils.c index 826e69976..1936a837a 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -1905,7 +1905,7 @@ void gv_cleanup_edge(edge_t * e) void gv_cleanup_node(node_t * n) { - if (ND_pos(n)) free(ND_pos(n)); + free(ND_pos(n)); if (ND_shape(n)) ND_shape(n)->fns->freefn(n); free_label(ND_label(n)); diff --git a/lib/dotgen/aspect.c b/lib/dotgen/aspect.c index 6d56d5553..2ffb1ef87 100644 --- a/lib/dotgen/aspect.c +++ b/lib/dotgen/aspect.c @@ -187,8 +187,7 @@ static void computeLayerWidths(graph_t * g) } free(layerWidthInfo[i].nodeGroupsInLayer); } - if (layerWidthInfo[i].removed) - free(layerWidthInfo[i].removed); + free(layerWidthInfo[i].removed); } free(layerWidthInfo); diff --git a/lib/dotgen/dotinit.c b/lib/dotgen/dotinit.c index 7b65868e9..0663a824c 100644 --- a/lib/dotgen/dotinit.c +++ b/lib/dotgen/dotinit.c @@ -145,8 +145,8 @@ dot_cleanup_graph(graph_t * g) dot_cleanup_graph(subg); } if (! agbindrec(g, "Agraphinfo_t", 0, TRUE)) return; - if (GD_clust(g)) free (GD_clust(g)); - if (GD_rankleader(g)) free (GD_rankleader(g)); + free (GD_clust(g)); + free (GD_rankleader(g)); free_list(GD_comp(g)); if (GD_rank(g)) { diff --git a/lib/fdpgen/layout.c b/lib/fdpgen/layout.c index 9cb8cf129..a1ad9178c 100644 --- a/lib/fdpgen/layout.c +++ b/lib/fdpgen/layout.c @@ -934,8 +934,7 @@ void layout(graph_t * g, layout_info * infop) bp = 0; infop->pack.fixed = bp; pts = putGraphs(c_cnt, cc, NULL, &infop->pack); - if (bp) - free(bp); + free(bp); } else { pts = NULL; if (c_cnt == 1) diff --git a/lib/glcomp/glcompfont.c b/lib/glcomp/glcompfont.c index 91f7ca966..f777a5abc 100644 --- a/lib/glcomp/glcompfont.c +++ b/lib/glcomp/glcompfont.c @@ -184,8 +184,7 @@ static glCompFont *glut_font_init(void) #endif void glDeleteFont(glCompFont * f) { - if (f->fontdesc) - free(f->fontdesc); + free(f->fontdesc); if (f->tex) glCompDeleteTexture(f->tex); free(f); diff --git a/lib/glcomp/glcomplabel.c b/lib/glcomp/glcomplabel.c index cbf1b3a9c..18e3353dc 100644 --- a/lib/glcomp/glcomplabel.c +++ b/lib/glcomp/glcomplabel.c @@ -67,8 +67,7 @@ static void update_font(glCompLabel * p,char* text,char* desc,int fs) p->common.font=glNewFont (p->common.compset,text,&p->common.color,temp->type,desc,fs,temp->is2D); if(temp) glDeleteFont(temp); - if(p->text) - free(p->text); + free(p->text); p->text = strdup(text); diff --git a/lib/glcomp/glcomptext.c b/lib/glcomp/glcomptext.c index 3a9062b16..a27c41350 100644 --- a/lib/glcomp/glcomptext.c +++ b/lib/glcomp/glcomptext.c @@ -291,8 +291,7 @@ void copy_font(glCompText * targetfont, const glCompText * sourcefont) targetfont->tIncX = sourcefont->tIncX; targetfont->tIncY = sourcefont->tIncY; targetfont->texId = sourcefont->texId; - if (targetfont->fontdesc) - free(targetfont->fontdesc); + free(targetfont->fontdesc); if (sourcefont->fontdesc != (char *) 0) targetfont->fontdesc = strdup(sourcefont->fontdesc); else @@ -402,8 +401,7 @@ void free_font_set(fontset_t * fontset) if (fontset->font_directory) rmdir(fontset->font_directory); #endif - if (fontset->font_directory) - free(fontset->font_directory); + free(fontset->font_directory); free(fontset); } diff --git a/lib/glcomp/glcomptexture.c b/lib/glcomp/glcomptexture.c index d3402bf3c..ed740ee88 100644 --- a/lib/glcomp/glcomptexture.c +++ b/lib/glcomp/glcomptexture.c @@ -162,12 +162,9 @@ void glCompDeleteTexture(glCompTex * t) return; t->userCount--; if (!t->userCount) { - if (t->data) - free(t->data); - if (t->def) - free(t->def); - if (t->text) - free(t->text); + free(t->data); + free(t->def); + free(t->text); free(t); } } diff --git a/lib/glcomp/glutils.c b/lib/glcomp/glutils.c index 058ed3e87..fad34ae07 100644 --- a/lib/glcomp/glutils.c +++ b/lib/glcomp/glutils.c @@ -413,8 +413,7 @@ void make_plane(glCompPoint a, glCompPoint b, glCompPoint c, plane * P) void replacestr(char *source, char **target) { - if (*target) - free(*target); + free(*target); *target = strdup(source); } diff --git a/lib/gvc/gvconfig.c b/lib/gvc/gvconfig.c index 78eecfa5b..9b0f1ac4e 100644 --- a/lib/gvc/gvconfig.c +++ b/lib/gvc/gvconfig.c @@ -615,8 +615,7 @@ globfree (glob_t* pglob) int i; for (i = 0; i < pglob->gl_pathc; i++) free (pglob->gl_pathv[i]); - if (pglob->gl_pathv) - free (pglob->gl_pathv); + free (pglob->gl_pathv); } #endif #endif diff --git a/lib/gvc/gvcontext.c b/lib/gvc/gvcontext.c index cff05cdd6..0c7966a12 100644 --- a/lib/gvc/gvcontext.c +++ b/lib/gvc/gvcontext.c @@ -95,10 +95,8 @@ int gvFreeContext(GVC_t * gvc) free(package); } gvjobs_delete(gvc); - if (gvc->config_path) - free(gvc->config_path); - if (gvc->input_filenames) - free(gvc->input_filenames); + free(gvc->config_path); + free(gvc->input_filenames); textfont_dict_close(gvc); for (i = 0; i != num_apis; ++i) { for (api = gvc->apis[i]; api != NULL; api = api_next) { diff --git a/lib/gvc/gvevent.c b/lib/gvc/gvevent.c index f1a7ec62b..fc68bba40 100644 --- a/lib/gvc/gvevent.c +++ b/lib/gvc/gvevent.c @@ -248,10 +248,8 @@ static void gvevent_enter_obj(GVJ_t * job) node_t *n; Agsym_t *a; - if (job->active_tooltip) { - free(job->active_tooltip); - job->active_tooltip = NULL; - } + free(job->active_tooltip); + job->active_tooltip = NULL; obj = job->current_obj; if (obj) { switch (agobjkind(obj)) { @@ -347,10 +345,8 @@ static void gvevent_select_current_obj(GVJ_t * job) } } - if (job->selected_href) { - free(job->selected_href); - job->selected_href = NULL; - } + free(job->selected_href); + job->selected_href = NULL; obj = job->selected_obj = job->current_obj; if (obj) { diff --git a/lib/gvc/gvjobs.c b/lib/gvc/gvjobs.c index f09b711f4..a6ade5a4f 100644 --- a/lib/gvc/gvjobs.c +++ b/lib/gvc/gvjobs.c @@ -118,8 +118,7 @@ void gv_argvlist_set_item(gv_argvlist_t *list, int index, char *item) void gv_argvlist_reset(gv_argvlist_t *list) { - if (list->argv) - free(list->argv); + free(list->argv); list->argv = NULL; list->alloc = 0; list->argc = 0; @@ -127,8 +126,7 @@ void gv_argvlist_reset(gv_argvlist_t *list) void gv_argvlist_free(gv_argvlist_t *list) { - if (list->argv) - free(list->argv); + free(list->argv); free(list); } @@ -141,10 +139,8 @@ void gvjobs_delete(GVC_t * gvc) job = job->next; gv_argvlist_reset(&(j->selected_obj_attributes)); gv_argvlist_reset(&(j->selected_obj_type_name)); - if (j->active_tooltip) - free(j->active_tooltip); - if (j->selected_href) - free(j->selected_href); + free(j->active_tooltip); + free(j->selected_href); free(j); } gvc->jobs = gvc->job = gvc->active_jobs = output_filename_job = output_langname_job = diff --git a/lib/neatogen/adjust.c b/lib/neatogen/adjust.c index 6734bc36c..c53c53973 100644 --- a/lib/neatogen/adjust.c +++ b/lib/neatogen/adjust.c @@ -764,7 +764,7 @@ SparseMatrix makeMatrix(Agraph_t* g, int dim, SparseMatrix *D) free(I); free(J); free(val); - if (valD) free (valD); + free (valD); return A; } diff --git a/lib/neatogen/delaunay.c b/lib/neatogen/delaunay.c index aa0c334ae..1bdfab2ea 100644 --- a/lib/neatogen/delaunay.c +++ b/lib/neatogen/delaunay.c @@ -897,10 +897,8 @@ v_data *UG_graph(double *x, double *y, int n, int accurate_computation) void freeGraph (v_data * graph) { if (graph != NULL) { - if (graph[0].edges != NULL) - free(graph[0].edges); - if (graph[0].ewgts != NULL) - free(graph[0].ewgts); + free(graph[0].edges); + free(graph[0].ewgts); free(graph); } } @@ -908,17 +906,13 @@ void freeGraph (v_data * graph) void freeGraphData(vtx_data * graph) { if (graph != NULL) { - if (graph[0].edges != NULL) - free(graph[0].edges); - if (graph[0].ewgts != NULL) - free(graph[0].ewgts); + free(graph[0].edges); + free(graph[0].ewgts); #ifdef USE_STYLES - if (graph[0].styles != NULL) - free(graph[0].styles); + free(graph[0].styles); #endif #ifdef DIGCOLA - if (graph[0].edists != NULL) - free(graph[0].edists); + free(graph[0].edists); #endif free(graph); } diff --git a/lib/neatogen/dijkstra.c b/lib/neatogen/dijkstra.c index e8fa818fb..c13a28fe7 100644 --- a/lib/neatogen/dijkstra.c +++ b/lib/neatogen/dijkstra.c @@ -91,7 +91,7 @@ static void mkHeap(heap * h, int size) static void freeHeap(heap * h) { - if (h->data) free(h->data); + free(h->data); } static void diff --git a/lib/neatogen/lu.c b/lib/neatogen/lu.c index c993f480d..48b99ed8c 100644 --- a/lib/neatogen/lu.c +++ b/lib/neatogen/lu.c @@ -73,11 +73,9 @@ int lu_decompose(double **a, int n) if (lu) free_array(lu); lu = new_array(n, n, 0.0); - if (ps) - free(ps); + free(ps); ps = N_NEW(n, int); - if (scales) - free(scales); + free(scales); scales = N_NEW(n, double); for (i = 0; i < n; i++) { /* For each row */ diff --git a/lib/neatogen/neatoinit.c b/lib/neatogen/neatoinit.c index 24720b88e..69c1e6407 100644 --- a/lib/neatogen/neatoinit.c +++ b/lib/neatogen/neatoinit.c @@ -1480,8 +1480,7 @@ void neato_layout(Agraph_t * g) pinfo.fixed = bp; pinfo.doSplines = 1; packGraphs(n_cc, cc, g, &pinfo); - if (bp) - free(bp); + free(bp); } else { neatoLayout(g, g, layoutMode, model, &am); diff --git a/lib/ortho/ortho.c b/lib/ortho/ortho.c index 39fc9edbf..122119a55 100644 --- a/lib/ortho/ortho.c +++ b/lib/ortho/ortho.c @@ -1158,7 +1158,7 @@ attachOrthoEdges (Agraph_t* g, maze* mp, int n_edges, route* route_list, splineI rte = route_list[irte]; npts = 1 + 3*rte.n; if (npts > splsz) { - if (ispline) free (ispline); + free (ispline); ispline = N_GNEW(npts, pointf); splsz = npts; } diff --git a/lib/osage/osageinit.c b/lib/osage/osageinit.c index 2d8dcae08..dfb04c473 100644 --- a/lib/osage/osageinit.c +++ b/lib/osage/osageinit.c @@ -164,9 +164,7 @@ layout (Agraph_t* g, int depth) /* pack rectangles */ pts = putRects (total, gs, &pinfo); - if (pinfo.vals) { - free (pinfo.vals); - } + free (pinfo.vals); rootbb.LL = pointfof(INT_MAX, INT_MAX); rootbb.UR = pointfof(-INT_MAX, -INT_MAX); diff --git a/lib/pathplan/cvt.c b/lib/pathplan/cvt.c index 5a0c56ddb..23a555059 100644 --- a/lib/pathplan/cvt.c +++ b/lib/pathplan/cvt.c @@ -150,10 +150,8 @@ int Pobspath(vconfig_t * config, Ppoint_t p0, int poly0, Ppoint_t p1, printDad(dad, config->N + 1); #endif - if (ptvis0) - free(ptvis0); - if (ptvis1) - free(ptvis1); + free(ptvis0); + free(ptvis1); output_route->pn = opn; output_route->ps = ops; diff --git a/lib/sfdpgen/PriorityQueue.c b/lib/sfdpgen/PriorityQueue.c index 41a356ca0..0a429bd32 100644 --- a/lib/sfdpgen/PriorityQueue.c +++ b/lib/sfdpgen/PriorityQueue.c @@ -47,9 +47,7 @@ void PriorityQueue_delete(PriorityQueue q){ free(q->buckets); } - if (q->where){ - free(q->where); - } + free(q->where); free(q->gain); free(q); diff --git a/lib/sfio/sfclose.c b/lib/sfio/sfclose.c index d8c2d0af0..0ba70e95a 100644 --- a/lib/sfio/sfclose.c +++ b/lib/sfio/sfclose.c @@ -108,10 +108,8 @@ int sfclose(Sfio_t * f) f->endb = f->endr = f->endw = f->next = f->data; /* zap any associated auxiliary buffer */ - if (f->rsrv) { - free(f->rsrv); - f->rsrv = NIL(Sfrsrv_t *); - } + free(f->rsrv); + f->rsrv = NIL(Sfrsrv_t *); /* delete any associated sfpopen-data */ if (f->proc) @@ -133,7 +131,6 @@ int sfclose(Sfio_t * f) } done: - if (data) - free(data); + free(data); return rv; } diff --git a/lib/sfio/sfmode.c b/lib/sfio/sfmode.c index a582320ee..23ff857f4 100644 --- a/lib/sfio/sfmode.c +++ b/lib/sfio/sfmode.c @@ -212,8 +212,7 @@ int _sfpclose(Sfio_t * f) return -1; f->proc = NIL(Sfproc_t *); - if (p->rdata) - free(p->rdata); + free(p->rdata); if (p->pid < 0) status = 0; @@ -254,8 +253,7 @@ static int _sfpmode(Sfio_t * f, int type) if (type == SF_WRITE) { /* save unread data */ p->ndata = f->endb - f->next; if (p->ndata > p->size) { - if (p->rdata) - free((char *) p->rdata); + free((char *) p->rdata); if ((p->rdata = malloc(p->ndata))) p->size = p->ndata; else { diff --git a/lib/sfio/sfvprintf.c b/lib/sfio/sfvprintf.c index 217ea7b53..c837a87ca 100644 --- a/lib/sfio/sfvprintf.c +++ b/lib/sfio/sfvprintf.c @@ -957,10 +957,8 @@ int sfvprintf(Sfio_t * f, const char *form, va_list args) } pop_fmt: - if (fp) { - free(fp); - fp = NIL(Fmtpos_t *); - } + free(fp); + fp = NIL(Fmtpos_t *); while ((fm = fmstk)) { /* pop the format stack and continue */ if (fm->eventf) { if (!form || !form[0]) @@ -984,8 +982,7 @@ int sfvprintf(Sfio_t * f, const char *form, va_list args) } done: - if (fp) - free(fp); + free(fp); while ((fm = fmstk)) { if (fm->eventf) (*fm->eventf) (f, SF_FINAL, NIL(void *), fm->ft); diff --git a/lib/sfio/sfvscanf.c b/lib/sfio/sfvscanf.c index 7707d184c..314565622 100644 --- a/lib/sfio/sfvscanf.c +++ b/lib/sfio/sfvscanf.c @@ -728,10 +728,8 @@ int sfvscanf(Sfio_t * f, const char *form, va_list args) } pop_fmt: - if (fp) { - free(fp); - fp = NIL(Fmtpos_t *); - } + free(fp); + fp = NIL(Fmtpos_t *); while ((fm = fmstk)) { /* pop the format stack and continue */ if (fm->eventf) { if (!form || !form[0]) @@ -755,8 +753,7 @@ int sfvscanf(Sfio_t * f, const char *form, va_list args) } done: - if (fp) - free(fp); + free(fp); while ((fm = fmstk)) { if (fm->eventf) (*fm->eventf) (f, SF_FINAL, NIL(void *), fm->ft); diff --git a/plugin/gd/gvrender_gd.c b/plugin/gd/gvrender_gd.c index 0660e45c3..165f09781 100644 --- a/plugin/gd/gvrender_gd.c +++ b/plugin/gd/gvrender_gd.c @@ -271,8 +271,7 @@ static void gdgen_missingfont(char *err, char *fontreq) agerr(AGERR, "%s : %s in %s\n", err, fontreq, p); #endif #endif - if (lastmissing) - free(lastmissing); + free(lastmissing); lastmissing = strdup(fontreq); n_errors++; #if 0 diff --git a/tclpkg/tclpathplan/tclpathplan.c b/tclpkg/tclpathplan/tclpathplan.c index 1e0cc20a0..9a8fb7f2e 100644 --- a/tclpkg/tclpathplan/tclpathplan.c +++ b/tclpkg/tclpathplan/tclpathplan.c @@ -238,8 +238,7 @@ static char *buildBindings(char *s1, char *s2) } } } else { - if (s1) - free(s1); + free(s1); l = strlen(s2); if (l) { s3 = malloc(l + 2); -- 2.40.0