]> granicus.if.org Git - graphviz/commitdiff
fix resource leakage in graphml2gv
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Sep 2020 03:15:51 +0000 (20:15 -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): [#def56]
  graphviz-2.40.1/cmd/tools/graphml2gv.c:729: alloc_fn: Storage is returned from allocation function "openFile".
  graphviz-2.40.1/cmd/tools/graphml2gv.c:676:5: alloc_fn: Storage is returned from allocation function "fopen".
  graphviz-2.40.1/cmd/tools/graphml2gv.c:676:5: var_assign: Assigning: "fp" = "fopen(name, mode)".
  graphviz-2.40.1/cmd/tools/graphml2gv.c:687:5: return_alloc: Returning allocated memory "fp".
  graphviz-2.40.1/cmd/tools/graphml2gv.c:729: var_assign: Assigning: "outFile" = storage returned from "openFile(optarg, "w")".
  graphviz-2.40.1/cmd/tools/graphml2gv.c:729: overwrite_var: Overwriting "outFile" in "outFile = openFile(optarg, "w")" leaks the storage that "outFile" points to.
  #  727|         break;
  #  728|     case 'o':
  #  729|->       outFile = openFile(optarg, "w");
  #  730|         break;
  #  731|     case ':':

Related to #1464.

cmd/tools/graphml2gv.c

index e2df20ccf5fc631f69d945e23aa2d3dba650bbb7..f30463f9d9cc56b35440968e7d3cda229988cc36 100644 (file)
@@ -723,6 +723,8 @@ static void initargs(int argc, char **argv)
            Verbose = 1;
            break;
        case 'o':
+           if (outFile != NULL)
+               fclose(outFile);
            outFile = openFile(optarg, "w");
            break;
        case ':':