Skip to content

Commit

Permalink
Close files and initialize variable as per cppcheck errors (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
livibetter authored and tsjensen committed Jan 8, 2017
1 parent 4576f96 commit d579540
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/boxes.c
Expand Up @@ -231,16 +231,20 @@ static int get_config_file()
return 1;
}
rc = is_dir (s);
if (rc == -1)
if (rc == -1) {
fclose (new_yyin);
return 1;
}
else if (rc) {
fprintf (stderr, "%s: Alleged config file '%s' is a directory "
"(taken from $BOXES)\n", PROJECT, s);
fclose (new_yyin);
return 1;
}
yyfilename = (char *) strdup (s);
if (yyfilename == NULL) {
perror (PROJECT);
fclose (new_yyin);
return 1;
}
yyin = new_yyin;
Expand All @@ -260,13 +264,16 @@ static int get_config_file()
new_yyin = fopen (BOXES_CONFIG, "r");
if (new_yyin) {
rc = is_dir (BOXES_CONFIG);
if (rc == -1)
if (rc == -1) {
fclose (new_yyin);
return 1;
}
else {
if (rc == 0) {
yyfilename = (char *) strdup (BOXES_CONFIG);
if (yyfilename == NULL) {
perror (PROJECT);
fclose (new_yyin);
return 1;
}
yyin = new_yyin;
Expand Down Expand Up @@ -320,17 +327,21 @@ static int get_config_file()
yyfilename = (char *) strdup (exepath);
#else
rc = is_dir (GLOBALCONF);
if (rc == -1)
if (rc == -1) {
fclose (new_yyin);
return 1;
}
else if (rc) {
fprintf (stderr, "%s: Alleged system-wide config file '%s' "
"is a directory\n", PROJECT, GLOBALCONF);
fclose (new_yyin);
return 1;
}
yyfilename = (char *) strdup (GLOBALCONF);
#endif
if (yyfilename == NULL) {
perror (PROJECT);
fclose (new_yyin);
return 1;
}
yyin = new_yyin;
Expand Down Expand Up @@ -477,7 +488,7 @@ static int process_commandline (int argc, char *argv[])
return 1;
}
else {
line_t templine;
line_t templine = {0};
templine.len = strlen (opt.cld);
templine.text = opt.cld;
if (empty_line(&templine)) {
Expand Down Expand Up @@ -513,16 +524,20 @@ static int process_commandline (int argc, char *argv[])
return 1;
}
rc = is_dir (optarg);
if (rc == -1)
if (rc == -1) {
fclose (f);
return 1;
}
else if (rc) {
fprintf (stderr, "%s: Alleged config file '%s' is a "
"directory\n", PROJECT, optarg);
fclose (f);
return 1;
}
yyfilename = (char *) strdup (optarg);
if (yyfilename == NULL) {
perror (PROJECT);
fclose (f);
return 1;
}
yyin = f;
Expand Down

0 comments on commit d579540

Please sign in to comment.