summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2018-04-12 22:46:35 +0200
committerHans Dedecker <dedeckeh@gmail.com>2018-04-12 22:46:35 +0200
commit36e4700668354d7c881b5e37f788cd3d21d02b47 (patch)
treef5239ecdfda6919b90f866ae8fd0987867132579
parent86a0e7c5e6934206e2f5624e2f8d3c3c25bf25b4 (diff)
handler: fix resource leak on error in netifd_init_script_handlers()
Detected by Coverity in CID 1412486 Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
-rw-r--r--handler.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/handler.c b/handler.c
index a0b2a57..8608a97 100644
--- a/handler.c
+++ b/handler.c
@@ -34,6 +34,9 @@ netifd_dir_push(int fd)
static void
netifd_dir_pop(int prev_fd)
{
+ if (prev_fd < 0)
+ return;
+
if (fchdir(prev_fd)) {}
close(prev_fd);
}
@@ -128,8 +131,10 @@ void netifd_init_script_handlers(int dir_fd, script_dump_cb cb)
int i, prev_fd;
prev_fd = netifd_dir_push(dir_fd);
- if (glob("./*.sh", 0, NULL, &g))
+ if (glob("./*.sh", 0, NULL, &g)) {
+ netifd_dir_pop(prev_fd);
return;
+ }
for (i = 0; i < g.gl_pathc; i++)
netifd_parse_script_handler(g.gl_pathv[i], cb);