From: Matthew Fernandez Date: Sun, 13 Sep 2020 01:34:55 +0000 (-0700) Subject: fix resource leak in country_graph_coloring_internal X-Git-Tag: 2.46.0~20^2^2~73^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8432ab9990a57d9e815db869c7ac756da78bb876;p=graphviz fix resource leak in country_graph_coloring_internal This addresses the following Coverity warnings: Error: CPPCHECK_WARNING (CWE-404): [#def16] graphviz-2.40.1/cmd/gvmap/country_graph_coloring.c:275: error[resourceLeak]: Resource leak: fp # 273| } # 274| } # 275|-> } # 276| # 277| void country_graph_coloring_internal(int seed, SparseMatrix A, int **p, real *norm_1, int do_swapping){ Error: RESOURCE_LEAK (CWE-772): [#def17] graphviz-2.40.1/cmd/gvmap/country_graph_coloring.c:237: alloc_fn: Storage is returned from allocation function "fopen". graphviz-2.40.1/cmd/gvmap/country_graph_coloring.c:237: var_assign: Assigning: "fp" = storage returned from "fopen("timing_greedy", "w")". graphviz-2.40.1/cmd/gvmap/country_graph_coloring.c:272: noescape: Resource "fp" is not freed or pointed-to in "fprintf". [Note: The source code implementation of the function has been overridden by a builtin model.] graphviz-2.40.1/cmd/gvmap/country_graph_coloring.c:275: leaked_storage: Variable "fp" going out of scope leaks the storage it points to. # 273| } # 274| } # 275|-> } # 276| # 277| void country_graph_coloring_internal(int seed, SparseMatrix A, int **p, real *norm_1, int do_swapping){ Related to #1464. --- diff --git a/cmd/gvmap/country_graph_coloring.c b/cmd/gvmap/country_graph_coloring.c index 4b4dc5e1e..9461b7568 100644 --- a/cmd/gvmap/country_graph_coloring.c +++ b/cmd/gvmap/country_graph_coloring.c @@ -269,6 +269,7 @@ void improve_antibandwidth_by_swapping(SparseMatrix A, int *p){ fprintf(fp,"%f %f %f\n", (real) (clock() - start)/(CLOCKS_PER_SEC), norm1[0], norm1[2]); } } + fclose(fp); } void country_graph_coloring_internal(int seed, SparseMatrix A, int **p, real *norm_1, int do_swapping){