diff --git a/libexec/rtld-elf/libmap.c b/libexec/rtld-elf/libmap.c --- a/libexec/rtld-elf/libmap.c +++ b/libexec/rtld-elf/libmap.c @@ -103,8 +103,9 @@ char *lm_map; struct stat st; ssize_t retval; - int fd; + int fd, errno_copy; + errno_copy = 0; TAILQ_FOREACH(p, &lmc_head, next) { if (strcmp(p->path, path) == 0) return; @@ -117,9 +118,9 @@ return; } if (fstat(fd, &st) == -1) { - close(fd); dbg("lm_parse_file: fstat(\"%s\") failed, %s", path, rtld_strerror(errno)); + close(fd); return; } @@ -132,14 +133,15 @@ lm_map = xmalloc(st.st_size); retval = read(fd, lm_map, st.st_size); + if (retval == -1) + errno_copy = errno; + close(fd); if (retval != st.st_size) { - close(fd); free(lm_map); dbg("lm_parse_file: read(\"%s\") failed, %s", path, - rtld_strerror(errno)); + rtld_strerror(errno_copy)); return; } - close(fd); p = xmalloc(sizeof(struct lmc)); p->path = xstrdup(path); p->dev = st.st_dev;