summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2017-05-19 19:56:43 +0000
committerEric Faurot <eric@cvs.openbsd.org>2017-05-19 19:56:43 +0000
commit34d343e7edcd590a28cff102ccb12176e2f0a599 (patch)
tree9f664d1d5f6abcad1093796f72de4735081f4e51 /usr.sbin
parent34ec4fd2e316feca598080b39ad957fc0d5f942a (diff)
- switch to recallocarray
- remove pre-allocation - use a better growth pattern ok gilles@ deraadt@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/smtpctl.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
index 412aebd6589..63dace2305a 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpctl.c,v 1.152 2017/01/09 09:53:23 reyk Exp $ */
+/* $OpenBSD: smtpctl.c,v 1.153 2017/05/19 19:56:42 eric Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@@ -396,26 +396,20 @@ static int
srv_iter_evpids(uint32_t msgid, uint64_t *evpid, int *offset)
{
static uint64_t *evpids = NULL, *tmp;
- static int n, alloc = 0;
+ static int n, tmpalloc, alloc = 0;
struct envelope evp;
- if (evpids == NULL) {
- alloc = 1000;
- evpids = calloc(alloc, sizeof(*evpids));
- if (evpids == NULL)
- err(1, "calloc");
- }
-
if (*offset == 0) {
n = 0;
while (srv_iter_envelopes(msgid, &evp)) {
if (n == alloc) {
- alloc += 256;
- tmp = reallocarray(evpids, alloc,
+ tmpalloc = alloc ? (alloc * 2) : 128;
+ tmp = recallocarray(evpids, alloc, tmpalloc,
sizeof(*evpids));
if (tmp == NULL)
- err(1, "reallocarray");
+ err(1, "recallocarray");
evpids = tmp;
+ alloc = tmpalloc;
}
evpids[n++] = evp.id;
}