From: Matthew Fernandez Date: Sun, 13 Sep 2020 03:23:07 +0000 (-0700) Subject: fix rersource leakage in sccmap X-Git-Tag: 2.46.0~20^2^2~73^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e4e345bf19016252bfd6a3f8f06c0ff9acf0ae46;p=graphviz fix rersource leakage in sccmap This addresses the following Coverity warning: Error: RESOURCE_LEAK (CWE-772): [#def69] graphviz-2.40.1/cmd/tools/sccmap.c:356: alloc_fn: Storage is returned from allocation function "openFile". graphviz-2.40.1/cmd/tools/sccmap.c:313:5: alloc_fn: Storage is returned from allocation function "fopen". graphviz-2.40.1/cmd/tools/sccmap.c:313:5: var_assign: Assigning: "fp" = "fopen(name, mode)". graphviz-2.40.1/cmd/tools/sccmap.c:323:5: return_alloc: Returning allocated memory "fp". graphviz-2.40.1/cmd/tools/sccmap.c:356: var_assign: Assigning: "outfp" = storage returned from "openFile(optarg, "w")". graphviz-2.40.1/cmd/tools/sccmap.c:356: overwrite_var: Overwriting "outfp" in "outfp = openFile(optarg, "w")" leaks the storage that "outfp" points to. Related to #1464. --- diff --git a/cmd/tools/sccmap.c b/cmd/tools/sccmap.c index 3f5dbd0f3..6918bf299 100644 --- a/cmd/tools/sccmap.c +++ b/cmd/tools/sccmap.c @@ -348,6 +348,8 @@ static void scanArgs(int argc, char **argv) wantDegenerateComp = 1; break; case 'o': + if (outfp != NULL) + fclose(outfp); outfp = openFile(optarg, "w"); break; case 'v':