[icinga-checkins] icinga.org: icinga-core/mfriedrich/workers: libicinga: avoid leaking filedescriptors on worker creation errors #2954

git at icinga.org git at icinga.org
Sun Aug 5 23:32:12 CEST 2012


Module: icinga-core
Branch: mfriedrich/workers
Commit: 0b960b58c916dada00d7aefc547eb7a04a0277df
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=0b960b58c916dada00d7aefc547eb7a04a0277df

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Sun Aug  5 14:21:02 2012 +0200

libicinga: avoid leaking filedescriptors on worker creation errors #2954

after forking, we should correctly close those fds, as well as close
them when bailing out to worker memory allocation errors.

refs #2954

---

 lib/worker.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/worker.c b/lib/worker.c
index 8518003..1aca1c3 100644
--- a/lib/worker.c
+++ b/lib/worker.c
@@ -673,17 +673,21 @@ struct worker_process *spawn_worker(void (*init_func)(void *), void *init_arg) {
 		return NULL;
 
 	pid = fork();
-	if (pid < 0)
+	if (pid < 0) {
+		close(sv[0]);
+		close(sv[1]);
 		return NULL;
+	}
 
 	/* parent leaves the child */
 	if (pid) {
 		worker_process *worker = calloc(1, sizeof(worker_process));
+		close(sv[1]);
 		if (!worker) {
 			kill(SIGKILL, pid);
+			close(sv[0]);
 			return NULL;
 		}
-		close(sv[1]);
 		worker->sd = sv[0];
 		worker->pid = pid;
 		worker->ioc = iocache_create(1 * 1024 * 1024);





More information about the icinga-checkins mailing list