]> granicus.if.org Git - graphviz/commitdiff
fix rersource leakage in sccmap
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Sep 2020 03:23:07 +0000 (20:23 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 19 Sep 2020 16:42:59 +0000 (09:42 -0700)
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.

cmd/tools/sccmap.c

index 3f5dbd0f36bfb0236ea6e834bbdd85ad4170588d..6918bf299187f2fdda495d2cacb36f06e7434359 100644 (file)
@@ -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':