From 2d9d388fba14659e5052a8658a1f36a257a84ad0 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Fri, 16 Jan 2009 15:09:53 +0100 Subject: [PATCH] Close some fds, original path from Trou. --- src/bip.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bip.c b/src/bip.c index 97c796f..6481f12 100644 --- a/src/bip.c +++ b/src/bip.c @@ -195,7 +195,9 @@ int do_pid_stuff(void) char hname[1024]; char longpath[1024]; FILE *f; + int fd; try_again: + fd = -1; f = fopen(conf_pid_file, "r"); if (f) goto pid_is_there; @@ -203,7 +205,6 @@ try_again: fatal("%s %s", "gethostname", strerror(errno)); snprintf(longpath, 1023, "%s.%s.%ld", conf_pid_file, hname, (long unsigned int)getpid()); - int fd; if ((fd = open(longpath, O_CREAT|O_WRONLY, S_IWUSR|S_IRUSR)) == -1) fatal("Cannot write to PID file (%s) %s", longpath, strerror(errno)); @@ -228,13 +229,14 @@ pid_is_there: if (c != 1 || p == 0) { mylog(LOG_INFO, "pid file found but invalid " "data inside. Continuing...\n"); - fclose(f); if (unlink(conf_pid_file)) { fatal("Cannot delete pid file '%s', " "check permissions.\n", conf_pid_file); } - close(fd); + fclose(f); + if (fd != -1) + close(fd); goto try_again; } } else