diff options
| author | Paul Eggert | 2013-07-18 03:24:26 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-07-18 03:24:26 -0700 |
| commit | 5e679a2cfdd8bc087dfd85fee252d8a4e5ed13c4 (patch) | |
| tree | 22bc75b259f54cbba617d35a7a9cbaf6c355c63f /src/filelock.c | |
| parent | e06ec67f56e7cce9b956e2882950379e96514266 (diff) | |
| download | emacs-5e679a2cfdd8bc087dfd85fee252d8a4e5ed13c4.tar.gz emacs-5e679a2cfdd8bc087dfd85fee252d8a4e5ed13c4.zip | |
* 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/filelock.c')
| -rw-r--r-- | src/filelock.c | 9 |
1 files changed, 3 insertions, 6 deletions
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 | |||
| 257 | get_boot_time_1 (const char *filename, bool newest) | 257 | get_boot_time_1 (const char *filename, bool newest) |
| 258 | { | 258 | { |
| 259 | struct utmp ut, *utp; | 259 | struct utmp ut, *utp; |
| 260 | int desc; | ||
| 261 | 260 | ||
| 262 | if (filename) | 261 | if (filename) |
| 263 | { | 262 | { |
| 264 | /* On some versions of IRIX, opening a nonexistent file name | 263 | /* On some versions of IRIX, opening a nonexistent file name |
| 265 | is likely to crash in the utmp routines. */ | 264 | is likely to crash in the utmp routines. */ |
| 266 | desc = emacs_open (filename, O_RDONLY, 0); | 265 | if (faccessat (AT_FDCWD, filename, R_OK, AT_EACCESS) != 0) |
| 267 | if (desc < 0) | ||
| 268 | return; | 266 | return; |
| 269 | 267 | ||
| 270 | emacs_close (desc); | ||
| 271 | |||
| 272 | utmpname (filename); | 268 | utmpname (filename); |
| 273 | } | 269 | } |
| 274 | 270 | ||
| @@ -512,7 +508,8 @@ read_lock_data (char *lfname, char lfinfo[MAX_LFINFO + 1]) | |||
| 512 | int fd = emacs_open (lfname, O_RDONLY | O_BINARY | O_NOFOLLOW, 0); | 508 | int fd = emacs_open (lfname, O_RDONLY | O_BINARY | O_NOFOLLOW, 0); |
| 513 | if (0 <= fd) | 509 | if (0 <= fd) |
| 514 | { | 510 | { |
| 515 | ptrdiff_t read_bytes = emacs_read (fd, lfinfo, MAX_LFINFO + 1); | 511 | /* Use read, not emacs_read, since FD isn't unwind-protected. */ |
| 512 | ptrdiff_t read_bytes = read (fd, lfinfo, MAX_LFINFO + 1); | ||
| 516 | int read_errno = errno; | 513 | int read_errno = errno; |
| 517 | if (emacs_close (fd) != 0) | 514 | if (emacs_close (fd) != 0) |
| 518 | return -1; | 515 | return -1; |