]> granicus.if.org Git - graphviz/commitdiff
fix resource leakage in gml2gv
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Sep 2020 03:13:23 +0000 (20:13 -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): [#def51]
  graphviz-2.40.1/cmd/tools/gml2gv.c:123: alloc_fn: Storage is returned from allocation function "openFile".
  graphviz-2.40.1/cmd/tools/gml2gv.c:68:5: alloc_fn: Storage is returned from allocation function "fopen".
  graphviz-2.40.1/cmd/tools/gml2gv.c:68:5: var_assign: Assigning: "fp" = "fopen(name, mode)".
  graphviz-2.40.1/cmd/tools/gml2gv.c:79:5: return_alloc: Returning allocated memory "fp".
  graphviz-2.40.1/cmd/tools/gml2gv.c:123: var_assign: Assigning: "outFile" = storage returned from "openFile(optarg, "w")".
  graphviz-2.40.1/cmd/tools/gml2gv.c:123: overwrite_var: Overwriting "outFile" in "outFile = openFile(optarg, "w")" leaks the storage that "outFile" points to.
  #  121|         break;
  #  122|     case 'o':
  #  123|->       outFile = openFile(optarg, "w");
  #  124|         break;
  #  125|     case ':':

Related to #1464.

cmd/tools/gml2gv.c

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