summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd
diff options
context:
space:
mode:
authorCharles Longeau <chl@cvs.openbsd.org>2012-09-27 17:47:50 +0000
committerCharles Longeau <chl@cvs.openbsd.org>2012-09-27 17:47:50 +0000
commit81aae5e403320a67be478330dac28a4b677cf737 (patch)
treec8d62788027aab843f438ba55d321c662d6703c4 /usr.sbin/smtpd
parent7f5180ef5dc4fccd1b734f28895d3fb30bf40f8c (diff)
use xmalloc()/xcalloc() helpers
while there unify usage of log_trace() in ramstat_set() ok gilles@ eric@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r--usr.sbin/smtpd/config.c16
-rw-r--r--usr.sbin/smtpd/control.c5
-rw-r--r--usr.sbin/smtpd/dns.c6
-rw-r--r--usr.sbin/smtpd/forward.c5
-rw-r--r--usr.sbin/smtpd/map_static.c19
-rw-r--r--usr.sbin/smtpd/map_stdio.c25
-rw-r--r--usr.sbin/smtpd/mda.c13
-rw-r--r--usr.sbin/smtpd/stat_ramstat.c14
8 files changed, 35 insertions, 68 deletions
diff --git a/usr.sbin/smtpd/config.c b/usr.sbin/smtpd/config.c
index 8e555898846..c4d77c8a77d 100644
--- a/usr.sbin/smtpd/config.c
+++ b/usr.sbin/smtpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.16 2012/08/19 14:16:57 chl Exp $ */
+/* $OpenBSD: config.c,v 1.17 2012/09/27 17:47:49 chl Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -126,11 +126,10 @@ init_pipes(void)
count = env->sc_instances[i] * env->sc_instances[j];
- if ((env->sc_pipes[i][j] =
- calloc(count, sizeof(int))) == NULL ||
- (env->sc_pipes[j][i] =
- calloc(count, sizeof(int))) == NULL)
- fatal(NULL);
+ env->sc_pipes[i][j] = xcalloc(count, sizeof(int),
+ "init_pipes");
+ env->sc_pipes[j][i] = xcalloc(count, sizeof(int),
+ "init_pipes");
while (--count >= 0) {
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC,
@@ -201,9 +200,8 @@ config_peers(struct peer *p, uint peercount)
if (dst == smtpd_process)
fatal("config_peers: cannot peer with oneself");
- if ((env->sc_ievs[dst] = calloc(env->sc_instances[dst],
- sizeof(struct imsgev))) == NULL)
- fatal("config_peers");
+ env->sc_ievs[dst] = xcalloc(env->sc_instances[dst],
+ sizeof(struct imsgev), "config_peers");
for (count = 0; count < env->sc_instances[dst]; count++) {
imsg_init(&(env->sc_ievs[dst][count].ibuf),
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c
index eecd564d7ba..d46c768a37b 100644
--- a/usr.sbin/smtpd/control.c
+++ b/usr.sbin/smtpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.73 2012/09/16 16:43:28 chl Exp $ */
+/* $OpenBSD: control.c,v 1.74 2012/09/27 17:47:49 chl Exp $ */
/*
* Copyright (c) 2012 Gilles Chehade <gilles@openbsd.org>
@@ -276,8 +276,7 @@ control_accept(int listenfd, short event, void *arg)
session_socket_blockmode(connfd, BM_NONBLOCK);
- if ((c = calloc(1, sizeof(*c))) == NULL)
- fatal(NULL);
+ c = xcalloc(1, sizeof(*c), "control_accept");
imsg_init(&c->iev.ibuf, connfd);
c->iev.handler = control_dispatch_ext;
c->iev.events = EV_READ;
diff --git a/usr.sbin/smtpd/dns.c b/usr.sbin/smtpd/dns.c
index 0818d6d7922..7dd13b49761 100644
--- a/usr.sbin/smtpd/dns.c
+++ b/usr.sbin/smtpd/dns.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dns.c,v 1.57 2012/08/25 10:23:11 gilles Exp $ */
+/* $OpenBSD: dns.c,v 1.58 2012/09/27 17:47:49 chl Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -352,9 +352,7 @@ dnssession_init(struct dns *query)
{
struct dnssession *s;
- s = calloc(1, sizeof(struct dnssession));
- if (s == NULL)
- fatal("dnssession_init: calloc");
+ s = xcalloc(1, sizeof(struct dnssession), "dnssession_init");
stat_increment("lka.session", 1);
diff --git a/usr.sbin/smtpd/forward.c b/usr.sbin/smtpd/forward.c
index 55d15682818..247cb000859 100644
--- a/usr.sbin/smtpd/forward.c
+++ b/usr.sbin/smtpd/forward.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: forward.c,v 1.30 2012/09/21 19:37:08 eric Exp $ */
+/* $OpenBSD: forward.c,v 1.31 2012/09/27 17:47:49 chl Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -53,8 +53,7 @@ forwards_get(int fd, struct expand *expand)
buf[len - 1] = '\0';
else {
/* EOF without EOL, copy and add the NUL */
- if ((lbuf = malloc(len + 1)) == NULL)
- fatal("malloc");
+ lbuf = xmalloc(len + 1, "forwards_get");
memcpy(lbuf, buf, len);
lbuf[len] = '\0';
buf = lbuf;
diff --git a/usr.sbin/smtpd/map_static.c b/usr.sbin/smtpd/map_static.c
index 646b1eb5d74..8aac67119ab 100644
--- a/usr.sbin/smtpd/map_static.c
+++ b/usr.sbin/smtpd/map_static.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map_static.c,v 1.6 2012/09/21 16:40:20 eric Exp $ */
+/* $OpenBSD: map_static.c,v 1.7 2012/09/27 17:47:49 chl Exp $ */
/*
* Copyright (c) 2012 Gilles Chehade <gilles@openbsd.org>
@@ -156,9 +156,8 @@ map_static_credentials(const char *key, char *line, size_t len)
return NULL;
*p++ = '\0';
- map_credentials = calloc(1, sizeof(struct map_credentials));
- if (map_credentials == NULL)
- fatalx("calloc");
+ map_credentials = xcalloc(1, sizeof *map_credentials,
+ "map_static_credentials");
if (strlcpy(map_credentials->username, line,
sizeof(map_credentials->username)) >=
@@ -185,9 +184,7 @@ map_static_alias(const char *key, char *line, size_t len)
struct map_alias *map_alias = NULL;
struct expandnode xn;
- map_alias = calloc(1, sizeof(struct map_alias));
- if (map_alias == NULL)
- fatalx("calloc");
+ map_alias = xcalloc(1, sizeof *map_alias, "map_static_alias");
while ((subrcpt = strsep(&line, ",")) != NULL) {
/* subrcpt: strip initial whitespace. */
@@ -224,9 +221,7 @@ map_static_virtual(const char *key, char *line, size_t len)
struct map_virtual *map_virtual = NULL;
struct expandnode xn;
- map_virtual = calloc(1, sizeof(struct map_virtual));
- if (map_virtual == NULL)
- fatalx("calloc");
+ map_virtual = xcalloc(1, sizeof *map_virtual, "map_static_virtual");
/* domain key, discard value */
if (strchr(key, '@') == NULL)
@@ -265,9 +260,7 @@ map_static_netaddr(const char *key, char *line, size_t len)
{
struct map_netaddr *map_netaddr = NULL;
- map_netaddr = calloc(1, sizeof(struct map_netaddr));
- if (map_netaddr == NULL)
- fatalx("calloc");
+ map_netaddr = xcalloc(1, sizeof *map_netaddr, "map_static_netaddr");
if (! text_to_netaddr(&map_netaddr->netaddr, line))
goto error;
diff --git a/usr.sbin/smtpd/map_stdio.c b/usr.sbin/smtpd/map_stdio.c
index faf84ce4e48..ba13aaa5cd2 100644
--- a/usr.sbin/smtpd/map_stdio.c
+++ b/usr.sbin/smtpd/map_stdio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map_stdio.c,v 1.9 2012/09/21 16:40:20 eric Exp $ */
+/* $OpenBSD: map_stdio.c,v 1.10 2012/09/27 17:47:49 chl Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -124,8 +124,7 @@ map_stdio_compare(void *hdl, const char *key, enum map_kind kind,
if (buf[flen - 1] == '\n')
buf[flen - 1] = '\0';
else {
- if ((lbuf = malloc(flen + 1)) == NULL)
- err(1, NULL);
+ lbuf = xmalloc(flen + 1, "map_stdio_compare");
memcpy(lbuf, buf, flen);
lbuf[flen] = '\0';
buf = lbuf;
@@ -163,8 +162,7 @@ map_stdio_get_entry(void *hdl, const char *key, size_t *len)
if (buf[flen - 1] == '\n')
buf[flen - 1] = '\0';
else {
- if ((lbuf = malloc(flen + 1)) == NULL)
- err(1, NULL);
+ lbuf = xmalloc(flen + 1, "map_stdio_get_entry");
memcpy(lbuf, buf, flen);
lbuf[flen] = '\0';
buf = lbuf;
@@ -219,9 +217,8 @@ map_stdio_credentials(const char *key, char *line, size_t len)
return NULL;
*p++ = '\0';
- map_credentials = calloc(1, sizeof(struct map_credentials));
- if (map_credentials == NULL)
- fatalx("calloc");
+ map_credentials = xcalloc(1, sizeof *map_credentials,
+ "map_stdio_credentials");
if (strlcpy(map_credentials->username, line,
sizeof(map_credentials->username)) >=
@@ -248,9 +245,7 @@ map_stdio_alias(const char *key, char *line, size_t len)
struct map_alias *map_alias = NULL;
struct expandnode xn;
- map_alias = calloc(1, sizeof(struct map_alias));
- if (map_alias == NULL)
- fatalx("calloc");
+ map_alias = xcalloc(1, sizeof *map_alias, "map_stdio_alias");
while ((subrcpt = strsep(&line, ",")) != NULL) {
/* subrcpt: strip initial whitespace. */
@@ -287,9 +282,7 @@ map_stdio_virtual(const char *key, char *line, size_t len)
struct map_virtual *map_virtual = NULL;
struct expandnode xn;
- map_virtual = calloc(1, sizeof(struct map_virtual));
- if (map_virtual == NULL)
- fatalx("calloc");
+ map_virtual = xcalloc(1, sizeof *map_virtual, "map_stdio_virtual");
/* domain key, discard value */
if (strchr(key, '@') == NULL)
@@ -327,9 +320,7 @@ map_stdio_netaddr(const char *key, char *line, size_t len)
{
struct map_netaddr *map_netaddr = NULL;
- map_netaddr = calloc(1, sizeof(struct map_netaddr));
- if (map_netaddr == NULL)
- fatalx("calloc");
+ map_netaddr = xcalloc(1, sizeof *map_netaddr, "map_stdio_netaddr");
if (! text_to_netaddr(&map_netaddr->netaddr, line))
goto error;
diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c
index ce6628feb3b..cc1549c278b 100644
--- a/usr.sbin/smtpd/mda.c
+++ b/usr.sbin/smtpd/mda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mda.c,v 1.76 2012/09/26 19:52:20 eric Exp $ */
+/* $OpenBSD: mda.c,v 1.77 2012/09/27 17:47:49 chl Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -82,9 +82,7 @@ mda_imsg(struct imsgev *iev, struct imsg *imsg)
}
/* make new session based on provided args */
- s = calloc(1, sizeof *s);
- if (s == NULL)
- fatal(NULL);
+ s = xcalloc(1, sizeof *s, "mda_imsg");
msgbuf_init(&s->w);
s->msg = *ep;
s->id = mda_id++;
@@ -175,9 +173,7 @@ mda_imsg(struct imsgev *iev, struct imsg *imsg)
if (ln[len - 1] == '\n')
ln[len - 1] = '\0';
else {
- buf = malloc(len + 1);
- if (buf == NULL)
- fatal(NULL);
+ buf = xmalloc(len + 1, "mda_imsg");
memcpy(buf, ln, len);
buf[len] = '\0';
ln = buf;
@@ -420,8 +416,7 @@ mda_check_loop(FILE *fp, struct envelope *ep)
buf[len - 1] = '\0';
else {
/* EOF without EOL, copy and add the NUL */
- if ((lbuf = malloc(len + 1)) == NULL)
- err(1, NULL);
+ lbuf = xmalloc(len + 1, "mda_check_loop");
memcpy(lbuf, buf, len);
lbuf[len] = '\0';
buf = lbuf;
diff --git a/usr.sbin/smtpd/stat_ramstat.c b/usr.sbin/smtpd/stat_ramstat.c
index 6d8e2737c50..43165214e5f 100644
--- a/usr.sbin/smtpd/stat_ramstat.c
+++ b/usr.sbin/smtpd/stat_ramstat.c
@@ -82,9 +82,7 @@ ramstat_increment(const char *name, size_t val)
strlcpy(lk.key, name, sizeof (lk.key));
np = RB_FIND(stats_tree, &stats, &lk);
if (np == NULL) {
- np = calloc(1, sizeof *np);
- if (np == NULL)
- fatal("calloc");
+ np = xcalloc(1, sizeof *np, "ramstat_increment");
strlcpy(np->key, name, sizeof (np->key));
RB_INSERT(stats_tree, &stats, np);
}
@@ -102,9 +100,7 @@ ramstat_decrement(const char *name, size_t val)
strlcpy(lk.key, name, sizeof (lk.key));
np = RB_FIND(stats_tree, &stats, &lk);
if (np == NULL) {
- np = calloc(1, sizeof *np);
- if (np == NULL)
- fatal("calloc");
+ np = xcalloc(1, sizeof *np, "ramstat_decrement");
strlcpy(np->key, name, sizeof (np->key));
RB_INSERT(stats_tree, &stats, np);
}
@@ -118,13 +114,11 @@ ramstat_set(const char *name, const struct stat_value *val)
{
struct ramstat_entry *np, lk;
- log_trace(TRACE_STAT, "ramstat: set");
+ log_trace(TRACE_STAT, "ramstat: set: %s", name);
strlcpy(lk.key, name, sizeof (lk.key));
np = RB_FIND(stats_tree, &stats, &lk);
if (np == NULL) {
- np = calloc(1, sizeof *np);
- if (np == NULL)
- fatal("calloc");
+ np = xcalloc(1, sizeof *np, "ramstat_set");
strlcpy(np->key, name, sizeof (np->key));
RB_INSERT(stats_tree, &stats, np);
}