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 @@ -133,10 +133,11 @@ lm_map = xmalloc(st.st_size); retval = read(fd, lm_map, st.st_size); if (retval != st.st_size) { - close(fd); free(lm_map); dbg("lm_parse_file: read(\"%s\") failed, %s", path, rtld_strerror(errno)); + /* Call close after errno is used. */ + close(fd); return; } close(fd);