From: Hans Dedecker Date: Thu, 12 Apr 2018 20:46:35 +0000 (+0200) Subject: handler: fix resource leak on error in netifd_init_script_handlers() X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=36e4700668354d7c881b5e37f788cd3d21d02b47;p=oweals%2Fnetifd.git handler: fix resource leak on error in netifd_init_script_handlers() Detected by Coverity in CID 1412486 Signed-off-by: Hans Dedecker --- 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);