Browse Source

Don't fclose() NULL pointer

Serj Kalichev 10 years ago
parent
commit
9c5451d588
1 changed files with 6 additions and 3 deletions
  1. 6 3
      bin/clish.c

+ 6 - 3
bin/clish.c

@@ -235,8 +235,11 @@ int main(int argc, char **argv)
 	}
 
 	/* Create shell instance */
-	if (quiet)
-		outfd = fopen("/dev/null", "w");
+	if (quiet) {
+		FILE *tmpfd = NULL;
+		if ((tmpfd = fopen("/dev/null", "w")))
+			outfd = tmpfd;
+	}
 	shell = clish_shell_new(NULL, outfd, stop_on_error);
 	if (!shell) {
 		fprintf(stderr, "Error: Can't run clish.\n");
@@ -344,7 +347,7 @@ end:
 		}
 		clish_shell_delete(shell);
 	}
-	if (quiet)
+	if (quiet && (outfd != stdout))
 		fclose(outfd);
 
 	/* Delete each cmds element */