svn rev #24329: trunk/src/kdc/

ghudson@MIT.EDU ghudson at MIT.EDU
Sun Sep 19 08:03:18 EDT 2010


http://src.mit.edu/fisheye/changelog/krb5/?cs=24329
Commit By: ghudson
Log Message:
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.



Changed Files:
U   trunk/src/kdc/main.c
Modified: trunk/src/kdc/main.c
===================================================================
--- trunk/src/kdc/main.c	2010-09-17 17:42:31 UTC (rev 24328)
+++ trunk/src/kdc/main.c	2010-09-19 12:03:18 UTC (rev 24329)
@@ -564,13 +564,16 @@
 
     /* 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 @@
         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 @@
                     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;
         }
 




More information about the cvs-krb5 mailing list