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 <kevin@kevinlocke.name>
This commit is contained in:
Kevin Locke 2016-09-12 21:03:30 -06:00
parent 7581417dfa
commit ba2c09e192

View file

@ -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)