Commit 54c1f793 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

- files.c:open_file() - Fix FD leak with file load error (David Benbennick)

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1390 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 149781d8
Showing with 12 additions and 12 deletions
+12 -12
......@@ -9,6 +9,9 @@ CVS Code -
do_cut_text()
- Fix incorrect cursor location when cutting long lines
(David Benbennick).
- files.c:
open_file()
- Fix FD leak with file load error (David Benbennick).
- nano.c:
main()
- Call load_file with arg 0 for insert, as we aren't really
......
......@@ -339,6 +339,14 @@ int open_file(const char *filename, int insert, int quiet)
statusbar(_("New File"));
new_file();
}
} else if (S_ISDIR(fileinfo.st_mode) || S_ISCHR(fileinfo.st_mode) ||
S_ISBLK(fileinfo.st_mode)) {
/* Don't open character or block files. Sorry, /dev/sndstat! */
statusbar(S_ISDIR(fileinfo.st_mode) ? _("\"%s\" is a directory") :
_("File \"%s\" is a device file"), filename);
if (!insert)
new_file();
return -1;
} else if ((fd = open(filename, O_RDONLY)) == -1) {
/* If we're in multibuffer mode, don't be quiet when an error
occurs while opening a file */
......@@ -352,23 +360,12 @@ int open_file(const char *filename, int insert, int quiet)
new_file();
return -1;
} else { /* File is A-OK */
if (S_ISDIR(fileinfo.st_mode) || S_ISCHR(fileinfo.st_mode) ||
S_ISBLK(fileinfo.st_mode)) {
if (S_ISDIR(fileinfo.st_mode))
statusbar(_("\"%s\" is a directory"), filename);
else
/* Don't open character or block files. Sorry, /dev/sndstat! */
statusbar(_("File \"%s\" is a device file"), filename);
if (!insert)
new_file();
return -1;
}
if (!quiet)
statusbar(_("Reading File"));
f = fdopen(fd, "rb"); /* Binary for our own line-end munging */
if (f == NULL) {
nperror("fdopen");
close(fd);
return -1;
}
read_file(f, filename, quiet);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment