summaryrefslogtreecommitdiff
path: root/daemon.c
diff options
context:
space:
mode:
authorTomas Korbar <tkorbar@redhat.com>2020-09-25 08:09:54 +0200
committerdormando <dormando@rydia.net>2021-06-07 22:02:59 -0700
commit683b286dafdfaf65bef21854e0561aae732a4ff4 (patch)
treebd14ba01bd9853f0dbaa01113cf2df7a8ee61068 /daemon.c
parent5ad7a83a77c36a6a57d856c0296af45897896753 (diff)
downloadmemcached-683b286dafdfaf65bef21854e0561aae732a4ff4.tar.gz
Fix leaking file descriptors
Another issue found by static code analysers
Diffstat (limited to 'daemon.c')
-rw-r--r--daemon.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/daemon.c b/daemon.c
index 0485453..3b6165f 100644
--- a/daemon.c
+++ b/daemon.c
@@ -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);
}