From b29d7ff6ac4025ecd59e01bdb908c6921d256303 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Mon, 21 Jun 2010 04:41:03 -0700 Subject: [PATCH] Early close for mapped files in libdwfl. --- libdwfl/ChangeLog | 2 ++ libdwfl/open.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 92be9488a..e71e33d67 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,7 @@ 2010-06-21 Roland McGrath + * open.c (__libdw_open_file): Close the fd when it's already mapped. + * dwfl_module_getsrc_file.: Update for Dwarf_Line member change. * dwfl_lineinfo.c: Likewise. Use dwarf_lineaddr. diff --git a/libdwfl/open.c b/libdwfl/open.c index 397af358f..063dece84 100644 --- a/libdwfl/open.c +++ b/libdwfl/open.c @@ -190,9 +190,13 @@ __libdw_open_file (int *fdp, Elf **elfp, bool close_on_fail, bool archive_ok) { elf_end (elf); elf = NULL; + close_fd = close_on_fail; } - if (error == DWFL_E_NOERROR ? close_fd : close_on_fail) + if (*fdp != -1 + && (close_fd || (close_on_fail + && elf->map_address != NULL + && elf_cntl (elf, ELF_C_FDREAD) == 0))) { close (*fdp); *fdp = -1; -- 2.47.2