Permalink
Browse files

"Resource acquired to 'global_fd' at line 388 may be lost here. Also

there is one similar error on line 388." (klocwork.com Issue #2). --
It also improves how the '-' parameter is parsed.

git-svn-id: svn://cherokee-project.com/cherokee/trunk@6648 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information...
alobbs committed May 21, 2011
1 parent 0fcdce9 commit 47b1d9331978fc94ff15c1ac203a52b35f86304c
Showing with 10 additions and 5 deletions.
  1. +10 −5 cget/main.c
View
@@ -376,14 +376,19 @@ main (int argc, char **argv)
return EXIT_OK;
case 'O':
- if (! strncmp (optarg, "-", 1)) {
+ if (global_fd != UNSET_FD) {
+ close (global_fd);
+ }
+
+ if ((strlen(optarg) == 1) && (optarg[0] == '-')) {
global_fd = fileno(stdout);
} else {
global_fd = open (optarg, O_WRONLY | O_CREAT, 0644);
- if (global_fd < 0) {
- PRINT_MSG ("ERROR: Can not open %s\n", optarg);
- return EXIT_ERROR;
- }
+ }
+
+ if (global_fd < 0) {
+ PRINT_MSG ("ERROR: Can not open %s\n", optarg);
+ return EXIT_ERROR;
}
break;

0 comments on commit 47b1d93

Please sign in to comment.