diff options
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | 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 @@ | |||
| 1 | 2013-07-18 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2013-07-18 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * filelock.c: Fix unlikely file descriptor leaks. | ||
| 4 | (get_boot_time_1): Rework to avoid using emacs_open. | ||
| 5 | This doesn't actually fix a leak, but is better anyway. | ||
| 6 | (read_lock_data): Use read, not emacs_read. | ||
| 7 | |||
| 3 | * doc.c: Fix minor memory and file descriptor leaks. | 8 | * doc.c: Fix minor memory and file descriptor leaks. |
| 4 | * doc.c (get_doc_string): Fix memory leak when doc file absent. | 9 | * doc.c (get_doc_string): Fix memory leak when doc file absent. |
| 5 | (get_doc_string, Fsnarf_documentation): | 10 | (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 | |||
| 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; |