This addresses the following Coverity warnings:
Error: RESOURCE_LEAK (CWE-772): [#def30]
graphviz-2.40.1/cmd/lefty/lefty.c:469: alloc_fn: Storage is returned from allocation function "fopen".
graphviz-2.40.1/cmd/lefty/lefty.c:469: var_assign: Assigning: "fp" = storage returned from "fopen(argv[0], "r")".
graphviz-2.40.1/cmd/lefty/lefty.c:464: overwrite_var: Overwriting "fp" in "fp = stdin" leaks the storage that "fp" points to.
# 462| usage(0);
# 463| else if (strcmp (argv[0], "-") == 0)
# 464|-> fp = stdin;
# 465| else if (argv[0][0] == '-') {
# 466| fprintf (stderr, "option %s unrecognized - ignored\n", argv[0]);
Error: RESOURCE_LEAK (CWE-772): [#def31]
graphviz-2.40.1/cmd/lefty/lefty.c:469: alloc_fn: Storage is returned from allocation function "fopen".
graphviz-2.40.1/cmd/lefty/lefty.c:469: var_assign: Assigning: "fp" = storage returned from "fopen(argv[0], "r")".
graphviz-2.40.1/cmd/lefty/lefty.c:469: overwrite_var: Overwriting "fp" in "fp = fopen(argv[0], "r")" leaks the storage that "fp" points to.
# 467| }
# 468| else {
# 469|-> if ((fp = fopen (argv[0], "r")) == NULL) {
# 470| fprintf (stderr, "cannot open input file: %s\n", argv[0]);
# 471| exit(2);
Related to #1464.
}
else if (strcmp (argv[0], "-?") == 0)
usage(0);
- else if (strcmp (argv[0], "-") == 0)
+ else if (strcmp (argv[0], "-") == 0) {
+ if (fp != NULL && fp != stdin)
+ fclose(fp);
fp = stdin;
- else if (argv[0][0] == '-') {
+ } else if (argv[0][0] == '-') {
fprintf (stderr, "option %s unrecognized - ignored\n", argv[0]);
}
else {
+ if (fp != NULL && fp != stdin)
+ fclose(fp);
if ((fp = fopen (argv[0], "r")) == NULL) {
fprintf (stderr, "cannot open input file: %s\n", argv[0]);
exit(2);