]> granicus.if.org Git - graphviz/commitdiff
fix resource leakage in unflatten
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Sep 2020 03:24:54 +0000 (20:24 -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): [#def70]
  graphviz-2.40.1/cmd/tools/unflatten.c:195: alloc_fn: Storage is returned from allocation function "openFile".
  graphviz-2.40.1/cmd/tools/unflatten.c:160:5: alloc_fn: Storage is returned from allocation function "fopen".
  graphviz-2.40.1/cmd/tools/unflatten.c:160:5: var_assign: Assigning: "fp" = "fopen(name, mode)".
  graphviz-2.40.1/cmd/tools/unflatten.c:170:5: return_alloc: Returning allocated memory "fp".
  graphviz-2.40.1/cmd/tools/unflatten.c:195: var_assign: Assigning: "outFile" = storage returned from "openFile(optarg, "w")".
  graphviz-2.40.1/cmd/tools/unflatten.c:195: overwrite_var: Overwriting "outFile" in "outFile = openFile(optarg, "w")" leaks the storage that "outFile" points to.
  #  193|         break;
  #  194|     case 'o':
  #  195|->       outFile = openFile(optarg, "w");
  #  196|         break;
  #  197|     case '?':

Related to #1464.

cmd/tools/unflatten.c

index 9658f51c1586a7ca59810324061768ebafd286af..d65d2d30447735a08e71e172fc9e9919c0526b90 100644 (file)
@@ -187,6 +187,8 @@ static char **scanargs(int argc, char **argv)
                ChainLimit = ival;
            break;
        case 'o':
+           if (outFile != NULL)
+               fclose(outFile);
            outFile = openFile(optarg, "w");
            break;
        case '?':