From d175f1d40a16f83912980a53649caf0a11ac4b75 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 18 Jul 2013 03:24:26 -0700 Subject: [PATCH] * filelock.c: Fix unlikely file descriptor leaks. (get_boot_time_1): Rework to avoid using emacs_open. This doesn't actually fix a leak, but is better anyway. (read_lock_data): Use read, not emacs_read. --- src/ChangeLog | 5 +++++ src/filelock.c | 9 +++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index cdc56419f63..8a1c163998b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2013-07-18 Paul Eggert + * filelock.c: Fix unlikely file descriptor leaks. + (get_boot_time_1): Rework to avoid using emacs_open. + This doesn't actually fix a leak, but is better anyway. + (read_lock_data): Use read, not emacs_read. + * doc.c: Fix minor memory and file descriptor leaks. * doc.c (get_doc_string): Fix memory leak when doc file absent. (get_doc_string, Fsnarf_documentation): diff --git a/src/filelock.c b/src/filelock.c index 4982dd3de13..fefd14b3a92 100644 --- a/src/filelock.c +++ b/src/filelock.c @@ -257,18 +257,14 @@ void get_boot_time_1 (const char *filename, bool newest) { struct utmp ut, *utp; - int desc; if (filename) { /* On some versions of IRIX, opening a nonexistent file name is likely to crash in the utmp routines. */ - desc = emacs_open (filename, O_RDONLY, 0); - if (desc < 0) + if (faccessat (AT_FDCWD, filename, R_OK, AT_EACCESS) != 0) return; - emacs_close (desc); - utmpname (filename); } @@ -512,7 +508,8 @@ read_lock_data (char *lfname, char lfinfo[MAX_LFINFO + 1]) int fd = emacs_open (lfname, O_RDONLY | O_BINARY | O_NOFOLLOW, 0); if (0 <= fd) { - ptrdiff_t read_bytes = emacs_read (fd, lfinfo, MAX_LFINFO + 1); + /* Use read, not emacs_read, since FD isn't unwind-protected. */ + ptrdiff_t read_bytes = read (fd, lfinfo, MAX_LFINFO + 1); int read_errno = errno; if (emacs_close (fd) != 0) return -1; -- 2.11.4.GIT