summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2013-07-18 03:24:26 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2013-07-18 03:24:26 -0700
commit5e679a2cfdd8bc087dfd85fee252d8a4e5ed13c4 (patch)
tree22bc75b259f54cbba617d35a7a9cbaf6c355c63f /src
parente06ec67f56e7cce9b956e2882950379e96514266 (diff)
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog5
-rw-r--r--src/filelock.c9
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 <eggert@cs.ucla.edu>
+ * 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;