diff --git a/cmd/gvmap/make_map.c b/cmd/gvmap/make_map.c index e628d6d4e9bf6741d14c5a67e95f1aa7e5288865..f085265ae23b77e9719735c56cc0e510bd06e443 100644 --- a/cmd/gvmap/make_map.c +++ b/cmd/gvmap/make_map.c @@ -891,8 +891,8 @@ void plot_dot_map(Agraph_t* gr, int n, int dim, real *x, SparseMatrix polys, Spa /* background color + plot label?*/ if (!gr) fprintf(f, "}\n"); - - + + FREE(sbuff); } #if 0 diff --git a/cmd/tools/graphml2gv.c b/cmd/tools/graphml2gv.c index b9fc9730c410c67160713d74f76e4e75bd33f486..e3ae1dbbac890aa91982dd1e32f71755af20445d 100644 --- a/cmd/tools/graphml2gv.c +++ b/cmd/tools/graphml2gv.c @@ -773,7 +773,7 @@ int main(int argc, char **argv) Agraph_t *G; Agraph_t *prev = 0; FILE *inFile; - int rv, gcnt = 0; + int rv = 0, gcnt = 0; #ifdef HAVE_EXPAT initargs(argc, argv); diff --git a/contrib/prune/generic_list.c b/contrib/prune/generic_list.c index cc856f42691fff7a3ce05eb84725ee89de147b5e..422caccbca55cf8f68584ef1cb8d2f96305af8a0 100644 --- a/contrib/prune/generic_list.c +++ b/contrib/prune/generic_list.c @@ -34,6 +34,7 @@ generic_list_t *new_generic_list(uint64_t size) list->data = (gl_data *) malloc(size * sizeof(gl_data)); if (list->data == NULL) { perror("[new_generic_list()] Error allocating memory:"); + free(list); return NULL; } } else diff --git a/lib/cgraph/agerror.c b/lib/cgraph/agerror.c index 718cefb407988d83146dea517a6f6ee7a6c1ddcb..d458f8f726855c23bf4151cfe45199113ad454d7 100644 --- a/lib/cgraph/agerror.c +++ b/lib/cgraph/agerror.c @@ -91,8 +91,10 @@ userout (agerrlevel_t level, const char *fmt, va_list args) bufsz = MAX(bufsz*2,n+1); if ((np = (char*)realloc(buf, bufsz)) == NULL) { fputs("userout: could not allocate memory\n", stderr ); + free(buf); return; } + buf = np; } va_end(args); } diff --git a/lib/gvpr/actions.c b/lib/gvpr/actions.c index fa4aff10a5f5a5fb4e160a86a8da4dfc2b442661..2d45f9bf724b0ae08dc6dde97a89bf3d39b6346c 100644 --- a/lib/gvpr/actions.c +++ b/lib/gvpr/actions.c @@ -338,7 +338,7 @@ static void cloneGraph(Agraph_t * tgt, Agraph_t * src) exerror("error cloning edge (%s,%s) from graph %s", agnameof(agtail(e)), agnameof(aghead(e)), agnameof(src)); - return; + goto done; } ep->key = e; ep->val = ne; @@ -352,6 +352,7 @@ static void cloneGraph(Agraph_t * tgt, Agraph_t * src) } } +done: dtclose (emap); free (data); } diff --git a/lib/gvpr/compile.c b/lib/gvpr/compile.c index 2a26336ee0c3384df939626b186911638731fabf..121a0b9055e53c49bb7c8773afbe5647880330f4 100644 --- a/lib/gvpr/compile.c +++ b/lib/gvpr/compile.c @@ -2473,8 +2473,10 @@ comp_prog *compileProg(parse_prog * inp, Gpr_t * state, int flags) if (flags) { endg_sfx = strdup (doFlags(flags, tmps)); - if (*endg_sfx == '\0') + if (*endg_sfx == '\0') { + free(endg_sfx); endg_sfx = 0; + } } if (!(initDisc(state))) diff --git a/lib/patchwork/patchwork.c b/lib/patchwork/patchwork.c index 9de4b2901324da5fbd8ce38948edf07b47e01a7f..6450906f9ef2803f06a677c60d5df83e74620c2e 100644 --- a/lib/patchwork/patchwork.c +++ b/lib/patchwork/patchwork.c @@ -261,11 +261,13 @@ static void walkTree(treenode_t * tree) static void freeTree (treenode_t* tp) { treenode_t* cp = tp->leftchild; + treenode_t* rp; int i, nc = tp->n_children; for (i = 0; i < nc; i++) { + rp = cp->rightsib; freeTree (cp); - cp = cp->rightsib; + cp = rp; } free (tp); } diff --git a/lib/sfdpgen/sfdpinit.c b/lib/sfdpgen/sfdpinit.c index 4b07a53237e3370dd4f8d83b9fbf504c092a8e0d..3e9ae243fd17ea8ca329f57771af6ba22de9f389 100644 --- a/lib/sfdpgen/sfdpinit.c +++ b/lib/sfdpgen/sfdpinit.c @@ -338,6 +338,9 @@ void sfdp_layout(graph_t * g) graphAdjustMode(g, &am, 0); #endif + pad.x = PS2INCH(DFLT_MARGIN); + pad.y = PS2INCH(DFLT_MARGIN); + if ((am.mode == AM_PRISM) && doAdjust) { doAdjust = 0; /* overlap removal done in sfdp */ ctrl->overlap = am.value; @@ -346,9 +349,6 @@ void sfdp_layout(graph_t * g) if (sep.doAdd) { pad.x = PS2INCH(sep.x); pad.y = PS2INCH(sep.y); - } else { - pad.x = PS2INCH(DFLT_MARGIN); - pad.y = PS2INCH(DFLT_MARGIN); } } else { diff --git a/lib/sparse/DotIO.c b/lib/sparse/DotIO.c index 6e89c5c4143ca75de723d68dd209deb287dbb9d5..a493a7858bc0fae4afba39e2d80f08f9f595d94a 100644 --- a/lib/sparse/DotIO.c +++ b/lib/sparse/DotIO.c @@ -178,19 +178,6 @@ SparseMatrix_import_dot (Agraph_t* g, int dim, real **label_sizes, real **x, int val = N_NEW(nedges, real); } - - if (format == FORMAT_COORD){ - A = SparseMatrix_new(i, i, nedges, MATRIX_TYPE_REAL, format); - A->nz = nedges; - I = A->ia; - J = A->ja; - val = (real*) A->a; - } else { - I = N_NEW(nedges, int); - J = N_NEW(nedges, int); - val = N_NEW(nedges, real); - } - sym = agattr(g, AGEDGE, "weight", NULL); if (D) { symD = agattr(g, AGEDGE, "len", NULL); @@ -297,7 +284,10 @@ SparseMatrix_import_dot (Agraph_t* g, int dim, real **label_sizes, real **x, int (*x)[i*dim+3] = ww; } else if (dim == 1){ nitems = sscanf(pval, "%lf", &xx); - if (nitems != 1) return NULL; + if (nitems != 1){ + A = NULL; + goto done; + } (*x)[i*dim] = xx; } else { assert(0); @@ -320,6 +310,7 @@ SparseMatrix_import_dot (Agraph_t* g, int dim, real **label_sizes, real **x, int if (D) *D = SparseMatrix_from_coordinate_arrays(nedges, nnodes, nnodes, I, J, valD, type, sz); +done: if (format != FORMAT_COORD){ FREE(I); FREE(J); diff --git a/lib/sparse/vector.c b/lib/sparse/vector.c index a8b401b802733cd589d2cde02abffaecd6447a19..798d690ab2314f2e949330afc302f3188bad6d7e 100644 --- a/lib/sparse/vector.c +++ b/lib/sparse/vector.c @@ -24,7 +24,10 @@ Vector Vector_new(int maxlen, size_t size_of_elem, void (*deallocator)(void *v)) v->size_of_elem = size_of_elem; v->deallocator = deallocator; v->v = malloc(size_of_elem*maxlen); - if (!v->v) return NULL; + if (!v->v){ + free(v); + return NULL; + } return v; } diff --git a/plugin/core/gvrender_core_mp.c b/plugin/core/gvrender_core_mp.c index d027d998012e831afc48d29ccc961efff5138553..a751a8080ab5900b7ff4512ef2e828e2b70dc99d 100644 --- a/plugin/core/gvrender_core_mp.c +++ b/plugin/core/gvrender_core_mp.c @@ -404,7 +404,7 @@ static void mp_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start, gvprintf(job, " %s\n", buffer); /* print points */ free(buffer); for (i = 0; i < count; i++) { - gvprintf(job, " %d", i % (count - 1) ? 1 : 0); /* -1 on all */ + gvprintf(job, " %d", i % (count + 1) ? 1 : 0); /* -1 on all */ } gvputs(job, "\n"); } diff --git a/plugin/core/gvrender_core_pic.c b/plugin/core/gvrender_core_pic.c index ec4ead3f43e98ea5d615f5d2300ee15decf49528..a2f790e07a309d5795f9346256d4f79030c8a691 100644 --- a/plugin/core/gvrender_core_pic.c +++ b/plugin/core/gvrender_core_pic.c @@ -475,7 +475,7 @@ static void pic_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start, gvprintf(job, " %s\n", buffer); /* print points */ free(buffer); for (i = 0; i < count; i++) { - gvprintf(job, " %d", i % (count - 1) ? 1 : 0); /* -1 on all */ + gvprintf(job, " %d", i % (count + 1) ? 1 : 0); /* -1 on all */ } gvputs(job, "\n"); }