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>
2 files changed