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

Related to #1464.

cmd/tools/cvtgxl.c

index 02f64824049f341abc9642cf12cd71da08a201e3..9081d4670ac33c384515912cd5d66f022d097b79 100644 (file)
@@ -150,6 +150,8 @@ static void initargs(int argc, char **argv)
            act = ToGXL;
            break;
        case 'o':
+           if (outFile != NULL)
+               fclose(outFile);
            outFile = openFile(optarg, "w");
            break;
        case ':':