From: Matthew Fernandez Date: Sun, 13 Sep 2020 01:32:36 +0000 (-0700) Subject: fix resource leak in edgepaint X-Git-Tag: 2.46.0~20^2^2~73^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c363fcf557bf0a38636fe6a20d097d394cf6f958;p=graphviz fix resource leak in edgepaint This addresses the following Coverity warning: Error: RESOURCE_LEAK (CWE-772): [#def15] graphviz-2.40.1/cmd/edgepaint/edgepaintmain.c:190: alloc_fn: Storage is returned from allocation function "openFile". graphviz-2.40.1/cmd/edgepaint/edgepaintmain.c:59:2: alloc_fn: Storage is returned from allocation function "fopen". graphviz-2.40.1/cmd/edgepaint/edgepaintmain.c:59:2: var_assign: Assigning: "fp" = "fopen(name, mode)". graphviz-2.40.1/cmd/edgepaint/edgepaintmain.c:69:2: return_alloc: Returning allocated memory "fp". graphviz-2.40.1/cmd/edgepaint/edgepaintmain.c:190: var_assign: Assigning: "outfile" = storage returned from "openFile(optarg, "w", CmdName)". graphviz-2.40.1/cmd/edgepaint/edgepaintmain.c:190: overwrite_var: Overwriting "outfile" in "outfile = openFile(optarg, "w", CmdName)" leaks the storage that "outfile" points to. # 188| break; # 189| case 'o': # 190|-> outfile = openFile(optarg, "w", CmdName); # 191| break; # 192| default: Related to #1464. --- diff --git a/cmd/edgepaint/edgepaintmain.c b/cmd/edgepaint/edgepaintmain.c index cfa4f95bd..3c19e11e4 100644 --- a/cmd/edgepaint/edgepaintmain.c +++ b/cmd/edgepaint/edgepaintmain.c @@ -175,6 +175,8 @@ static void init(int argc, char *argv[], real *angle, real *accuracy, char **inf Verbose = TRUE; break; case 'o': + if (outfile != NULL) + fclose(outfile); outfile = openFile(optarg, "w", CmdName); break; default: