]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libdwfl: Fix fd leak/closing wrong fd after dwfl_core_file_report()
authorOmar Sandoval <osandov@fb.com>
Mon, 5 Aug 2019 10:40:05 +0000 (03:40 -0700)
committerMark Wielaard <mark@klomp.org>
Fri, 9 Aug 2019 20:31:18 +0000 (22:31 +0200)
commitd37f6ea7e3e544e27b6067405a6b5ab0a31a99c8
tree0639315f0dd20daf2a3e46b146db9bc39721bcd8
parent1b1433d5670b75c4bd5c9b598e0b00fba6e82d90
libdwfl: Fix fd leak/closing wrong fd after dwfl_core_file_report()

dwfl_segment_report_module() (used only by dwfl_core_file_report())
opens a file descriptor and/or an Elf handle, reports a module, and
assigns mod->main.elf. However, it doesn't assign mod->main.fd, so it is
left as 0. This causes two problems:

1. We leak the file descriptor for the module.
2. When we free the module, we close file descriptor 0 (stdin).

Fix it by assigning mod->main.fd.

Signed-off-by: Omar Sandoval <osandov@fb.com>
libdwfl/ChangeLog
libdwfl/dwfl_segment_report_module.c