commit 54c1f7932cf26c9a87f4de789b3667642a990940
parent 149781d8270aec3146970a1095c8c59d5e50837c
Author: Chris Allegretta <chrisa@asty.org>
Date: Sun, 26 Jan 2003 04:11:09 +0000
- 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
Diffstat:
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -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
diff --git a/files.c b/files.c
@@ -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);