[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r113445: * term.c: Fix minor fdopen-related file des
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] trunk r113445: * term.c: Fix minor fdopen-related file descriptor leaks. |
Date: |
Thu, 18 Jul 2013 08:35:32 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 113445
revision-id: address@hidden
parent: address@hidden
author: Paul Eggert <address@hidden>
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Thu 2013-07-18 01:35:27 -0700
message:
* term.c: Fix minor fdopen-related file descriptor leaks.
* term.c (Fresume_tty) [!MSDOS]: Close fd if fdopen (fd) fails.
(init_tty) [!DOS_NT]: Likewise. Also close fd if isatty (fd) fails.
modified:
src/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1438
src/term.c term.c-20091113204419-o5vbwnq5f7feedwu-220
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2013-07-18 02:12:59 +0000
+++ b/src/ChangeLog 2013-07-18 08:35:27 +0000
@@ -1,5 +1,9 @@
2013-07-18 Paul Eggert <address@hidden>
+ * term.c: Fix minor fdopen-related file descriptor leaks.
+ * term.c (Fresume_tty) [!MSDOS]: Close fd if fdopen (fd) fails.
+ (init_tty) [!DOS_NT]: Likewise. Also close fd if isatty (fd) fails.
+
* charset.c: Fix file descriptor leaks and errno issues.
Include <errno.h>.
(load_charset_map_from_file): Don't leak file descriptor on error.
=== modified file 'src/term.c'
--- a/src/term.c 2013-07-12 02:03:47 +0000
+++ b/src/term.c 2013-07-18 08:35:27 +0000
@@ -2416,15 +2416,20 @@
t->display_info.tty->input = stdin;
#else /* !MSDOS */
fd = emacs_open (t->display_info.tty->name, O_RDWR | O_NOCTTY, 0);
+ t->display_info.tty->input = t->display_info.tty->output
+ = fd < 0 ? 0 : fdopen (fd, "w+");
- if (fd == -1)
- error ("Can not reopen tty device %s: %s", t->display_info.tty->name,
strerror (errno));
+ if (! t->display_info.tty->input)
+ {
+ int open_errno = errno;
+ emacs_close (fd);
+ report_file_errno ("Cannot reopen tty device",
+ build_string (t->display_info.tty->name),
+ open_errno);
+ }
if (!O_IGNORE_CTTY && strcmp (t->display_info.tty->name, DEV_TTY) != 0)
dissociate_if_controlling_tty (fd);
-
- t->display_info.tty->output = fdopen (fd, "w+");
- t->display_info.tty->input = t->display_info.tty->output;
#endif
add_keyboard_wait_descriptor (fd);
@@ -2990,7 +2995,6 @@
{
/* Open the terminal device. */
- FILE *file;
/* If !ctty, don't recognize it as our controlling terminal, and
don't make it the controlling tty if we don't have one now.
@@ -3001,30 +3005,21 @@
open a frame on the same terminal. */
int flags = O_RDWR | O_NOCTTY | (ctty ? 0 : O_IGNORE_CTTY);
int fd = emacs_open (name, flags, 0);
+ tty->input = tty->output = fd < 0 || ! isatty (fd) ? 0 : fdopen (fd, "w+");
+
+ if (! tty->input)
+ {
+ char const *diagnostic
+ = tty->input ? "Not a tty device: %s" : "Could not open file: %s";
+ emacs_close (fd);
+ maybe_fatal (must_succeed, terminal, diagnostic, diagnostic, name);
+ }
tty->name = xstrdup (name);
terminal->name = xstrdup (name);
- if (fd < 0)
- maybe_fatal (must_succeed, terminal,
- "Could not open file: %s",
- "Could not open file: %s",
- name);
- if (!isatty (fd))
- {
- emacs_close (fd);
- maybe_fatal (must_succeed, terminal,
- "Not a tty device: %s",
- "Not a tty device: %s",
- name);
- }
-
if (!O_IGNORE_CTTY && !ctty)
dissociate_if_controlling_tty (fd);
-
- file = fdopen (fd, "w+");
- tty->input = file;
- tty->output = file;
}
tty->type = xstrdup (terminal_type);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r113445: * term.c: Fix minor fdopen-related file descriptor leaks.,
Paul Eggert <=