diff options
author | Tomas Korbar <tkorbar@redhat.com> | 2020-09-25 08:09:54 +0200 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2021-06-07 22:02:59 -0700 |
commit | 683b286dafdfaf65bef21854e0561aae732a4ff4 (patch) | |
tree | bd14ba01bd9853f0dbaa01113cf2df7a8ee61068 | |
parent | 5ad7a83a77c36a6a57d856c0296af45897896753 (diff) | |
download | memcached-683b286dafdfaf65bef21854e0561aae732a4ff4.tar.gz |
Fix leaking file descriptors
Another issue found by static code analysers
-rw-r--r-- | daemon.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -67,23 +67,25 @@ int daemonize(int nochdir, int noclose) if (noclose == 0 && (fd = open("/dev/null", O_RDWR, 0)) != -1) { if(dup2(fd, STDIN_FILENO) < 0) { perror("dup2 stdin"); - return (-1); + goto err_cleanup; } if(dup2(fd, STDOUT_FILENO) < 0) { perror("dup2 stdout"); - return (-1); + goto err_cleanup; } if(dup2(fd, STDERR_FILENO) < 0) { perror("dup2 stderr"); - return (-1); + goto err_cleanup; } - if (fd > STDERR_FILENO) { - if(close(fd) < 0) { - perror("close"); - return (-1); - } + if(close(fd) < 0) { + perror("close"); + return (-1); } } return (0); + + err_cleanup: + close(fd); + return (-1); } |