diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2018-04-12 22:46:35 +0200 |
---|---|---|
committer | Hans Dedecker <dedeckeh@gmail.com> | 2018-04-12 22:46:35 +0200 |
commit | 36e4700668354d7c881b5e37f788cd3d21d02b47 (patch) | |
tree | f5239ecdfda6919b90f866ae8fd0987867132579 | |
parent | 86a0e7c5e6934206e2f5624e2f8d3c3c25bf25b4 (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.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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); |