From 4b365b97f7972f6a18f14e286017a25404b4179b Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Sun, 19 Sep 2010 12:03:18 +0000 Subject: [PATCH] Slight revisions to create_workers() in the KDC: * Use calloc() to allocate the pids array; squashes a Coverity false positive. * Don't leak the pids array in worker processes. * Use consistent terminology in comments. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24329 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kdc/main.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/kdc/main.c b/src/kdc/main.c index 6aac1d8fc..8d5d9a800 100644 --- a/src/kdc/main.c +++ b/src/kdc/main.c @@ -564,13 +564,16 @@ create_workers(int num) /* Create child worker processes; return in each child. */ krb5_klog_syslog(LOG_INFO, "creating %d worker processes", num); - pids = malloc(num * sizeof(pid_t)); + pids = calloc(num, sizeof(pid_t)); if (pids == NULL) return ENOMEM; for (i = 0; i < num; i++) { pid = fork(); - if (pid == 0) + if (pid == 0) { + /* Return control to main() in the new worker process. */ + free(pids); return 0; + } if (pid == -1) { /* Couldn't fork enough times. */ status = errno; @@ -581,10 +584,10 @@ create_workers(int num) pids[i] = pid; } - /* Supervise the child processes. */ + /* Supervise the worker processes. */ numleft = num; while (!signal_requests_exit) { - /* Wait until a child process exits or we get a signal. */ + /* Wait until a worker process exits or we get a signal. */ pid = wait(&status); if (pid >= 0) { krb5_klog_syslog(LOG_ERR, "worker %ld exited with status %d", @@ -596,8 +599,8 @@ create_workers(int num) pids[i] = -1; } - /* When one process exits, terminate them all, so that KDC crashes - * behave similarly with or without worker processes. */ + /* When one worker process exits, terminate them all, so that KDC + * crashes behave similarly with or without worker processes. */ break; } -- 2.26.2