kdc: start_kdc avoid warning

The prior structure of the code was safe but can appear otherwise to
static analyzers since the assignment to pids[i] occurs after exitting
the for() loop.

While here use calloc() instead of malloc()/memset().

Change-Id: I8455aa259fd8c7c17778827937ec26127fe0785c
This commit is contained in:
Jeffrey Altman
2016-11-19 09:57:14 -05:00
parent 989a7c3379
commit a1d3ab05c4

View File

@@ -1116,10 +1116,9 @@ start_kdc(krb5_context context,
if (max_kdcs < 1)
max_kdcs = 1;
pids = malloc(max_kdcs * sizeof(*pids));
pids = calloc(max_kdcs, sizeof(*pids));
if (!pids)
krb5_err(context, 1, errno, "malloc");
memset(pids, 0x0, max_kdcs * sizeof(*pids));
/*
* We open a socketpair of which we hand one end to each of our kids.
@@ -1190,10 +1189,12 @@ start_kdc(krb5_context context,
sleep(10);
break;
default:
for (i=0; i < max_kdcs; i++)
if (pids[i] == 0)
break;
for (i=0; i < max_kdcs; i++) {
if (pids[i] == 0) {
pids[i] = pid;
break;
}
}
kdc_log(context, config, 0, "KDC worker process started: %d", pid);
num_kdcs++;
gettimeofday(&tv1, NULL);