]> granicus.if.org Git - graphviz/commitdiff
fix resource leak in edgepaint
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Sep 2020 01:32:36 +0000 (18:32 -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): [#def15]
  graphviz-2.40.1/cmd/edgepaint/edgepaintmain.c:190: alloc_fn: Storage is returned from allocation function "openFile".
  graphviz-2.40.1/cmd/edgepaint/edgepaintmain.c:59:2: alloc_fn: Storage is returned from allocation function "fopen".
  graphviz-2.40.1/cmd/edgepaint/edgepaintmain.c:59:2: var_assign: Assigning: "fp" = "fopen(name, mode)".
  graphviz-2.40.1/cmd/edgepaint/edgepaintmain.c:69:2: return_alloc: Returning allocated memory "fp".
  graphviz-2.40.1/cmd/edgepaint/edgepaintmain.c:190: var_assign: Assigning: "outfile" = storage returned from "openFile(optarg, "w", CmdName)".
  graphviz-2.40.1/cmd/edgepaint/edgepaintmain.c:190: overwrite_var: Overwriting "outfile" in "outfile = openFile(optarg, "w", CmdName)" leaks the storage that "outfile" points to.
  #  188|         break;
  #  189|       case 'o':
  #  190|->       outfile = openFile(optarg, "w", CmdName);
  #  191|         break;
  #  192|       default:

Related to #1464.

cmd/edgepaint/edgepaintmain.c

index cfa4f95bd7be01be31a8b4f8bfea30ebf3b2eb2c..3c19e11e4fac4d71a7ae35569d8c278ec20a10db 100644 (file)
@@ -175,6 +175,8 @@ static void init(int argc, char *argv[], real *angle, real *accuracy, char **inf
       Verbose = TRUE;
       break;
     case 'o':
+      if (outfile != NULL)
+        fclose(outfile);
       outfile = openFile(optarg, "w", CmdName);
       break;
     default: