From ba2c09e1927a1e67269ce1325929cd9f1af1d318 Mon Sep 17 00:00:00 2001 From: Kevin Locke Date: Mon, 12 Sep 2016 21:03:30 -0600 Subject: [PATCH] section: Close FD in open_module_self on error If open_module_map encounters an error, open_module_self would return 0 while leaving the file descriptor open. Since close_module does not validate the state of the mod_handle, callers can't know whether to call close_module when this occurs. Resolve this by closing the file descriptor before returning so that mod_handle is never partially open. Signed-off-by: Kevin Locke --- src/compat/section-elf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compat/section-elf.c b/src/compat/section-elf.c index 516be36..680935c 100644 --- a/src/compat/section-elf.c +++ b/src/compat/section-elf.c @@ -123,7 +123,12 @@ int open_module_self(mod_handle *mod) return 0; mod->fd = fd; - return open_module_map(mod); + if (!open_module_map(mod)) { + close(mod->fd); + return 0; + } + + return 1; } void close_module(mod_handle *mod)