summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhshoexer <hshoexer@openbsd.org>2007-09-13 21:00:14 +0000
committerhshoexer <hshoexer@openbsd.org>2007-09-13 21:00:14 +0000
commit2d77548fb79506dc094270ac6c75d8918a30c889 (patch)
tree34cc96999745031cccaf1848293e7c7e8987af81
parentMALLOC/FREE -> malloc/free and M_ZERO changes (diff)
downloadwireguard-openbsd-2d77548fb79506dc094270ac6c75d8918a30c889.tar.xz
wireguard-openbsd-2d77548fb79506dc094270ac6c75d8918a30c889.zip
Convert MALLOC/FREE to malloc/free and use M_ZERO where applicable.
ok krw@
-rw-r--r--sys/net/pfkey.c5
-rw-r--r--sys/net/pfkeyv2.c51
-rw-r--r--sys/net/pfkeyv2_convert.c23
3 files changed, 29 insertions, 50 deletions
diff --git a/sys/net/pfkey.c b/sys/net/pfkey.c
index a6dcf60db03..7b6f92a8792 100644
--- a/sys/net/pfkey.c
+++ b/sys/net/pfkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkey.c,v 1.16 2004/11/26 18:02:22 markus Exp $ */
+/* $OpenBSD: pfkey.c,v 1.17 2007/09/13 21:00:14 hshoexer Exp $ */
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
@@ -201,9 +201,8 @@ pfkey_attach(struct socket *socket, struct mbuf *proto)
int s;
if (!(socket->so_pcb = malloc(sizeof(struct rawcb),
- M_PCB, M_DONTWAIT)))
+ M_PCB, M_DONTWAIT | M_ZERO)))
return (ENOMEM);
- bzero(socket->so_pcb, sizeof(struct rawcb));
s = splnet();
rval = raw_usrreq(socket, PRU_ATTACH, NULL, proto, NULL);
diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c
index a6bba0895ac..6a4d73324f8 100644
--- a/sys/net/pfkeyv2.c
+++ b/sys/net/pfkeyv2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkeyv2.c,v 1.116 2007/09/01 18:49:28 henning Exp $ */
+/* $OpenBSD: pfkeyv2.c,v 1.117 2007/09/13 21:00:14 hshoexer Exp $ */
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
@@ -152,10 +152,9 @@ pfkeyv2_create(struct socket *socket)
struct pfkeyv2_socket *pfkeyv2_socket;
if (!(pfkeyv2_socket = malloc(sizeof(struct pfkeyv2_socket),
- M_PFKEY, M_DONTWAIT)))
+ M_PFKEY, M_DONTWAIT | M_ZERO)))
return (ENOMEM);
- bzero(pfkeyv2_socket, sizeof(struct pfkeyv2_socket));
pfkeyv2_socket->next = pfkeyv2_sockets;
pfkeyv2_socket->socket = socket;
pfkeyv2_socket->pid = curproc->p_pid;
@@ -381,13 +380,11 @@ pfkeyv2_policy(struct ipsec_acquire *ipa, void **headers, void **buffer)
return (EINVAL);
}
- if (!(p = malloc(i, M_PFKEY, M_DONTWAIT))) {
+ if (!(p = malloc(i, M_PFKEY, M_DONTWAIT | M_ZERO))) {
rval = ENOMEM;
goto ret;
- } else {
+ } else
*buffer = p;
- bzero(p, i);
- }
if (dir == IPSP_DIRECTION_OUT)
headers[SADB_X_EXT_SRC_FLOW] = p;
@@ -596,13 +593,11 @@ pfkeyv2_get(struct tdb *sa, void **headers, void **buffer, int *lenp)
goto ret;
}
- if (!(p = malloc(i, M_PFKEY, M_DONTWAIT))) {
+ if (!(p = malloc(i, M_PFKEY, M_DONTWAIT | M_ZERO))) {
rval = ENOMEM;
goto ret;
- } else {
+ } else
*buffer = p;
- bzero(p, i);
- }
headers[SADB_EXT_SA] = p;
@@ -939,12 +934,11 @@ pfkeyv2_send(struct socket *socket, void *message, int len)
/* Send a message back telling what the SA (the SPI really) is */
if (!(freeme = malloc(sizeof(struct sadb_sa), M_PFKEY,
- M_DONTWAIT))) {
+ M_DONTWAIT | M_ZERO))) {
rval = ENOMEM;
goto ret;
}
- bzero(freeme, sizeof(struct sadb_sa));
headers[SADB_EXT_SPIRANGE] = NULL;
headers[SADB_EXT_SA] = freeme;
bckptr = freeme;
@@ -1316,13 +1310,11 @@ pfkeyv2_send(struct socket *socket, void *message, int len)
i = sizeof(struct sadb_supported) + sizeof(ealgs);
- if (!(freeme = malloc(i, M_PFKEY, M_DONTWAIT))) {
+ if (!(freeme = malloc(i, M_PFKEY, M_DONTWAIT | M_ZERO))) {
rval = ENOMEM;
goto ret;
}
- bzero(freeme, i);
-
ssup = (struct sadb_supported *) freeme;
ssup->sadb_supported_len = i / sizeof(uint64_t);
@@ -1336,7 +1328,7 @@ pfkeyv2_send(struct socket *socket, void *message, int len)
i = sizeof(struct sadb_supported) + sizeof(aalgs);
- if (!(freeme = malloc(i, M_PFKEY, M_DONTWAIT))) {
+ if (!(freeme = malloc(i, M_PFKEY, M_DONTWAIT | M_ZERO))) {
rval = ENOMEM;
goto ret;
}
@@ -1344,8 +1336,6 @@ pfkeyv2_send(struct socket *socket, void *message, int len)
/* Keep track what this socket has registered for */
pfkeyv2_socket->registration |= (1 << ((struct sadb_msg *)message)->sadb_msg_satype);
- bzero(freeme, i);
-
ssup = (struct sadb_supported *) freeme;
ssup->sadb_supported_len = i / sizeof(uint64_t);
@@ -1359,13 +1349,11 @@ pfkeyv2_send(struct socket *socket, void *message, int len)
i = sizeof(struct sadb_supported) + sizeof(calgs);
- if (!(freeme = malloc(i, M_PFKEY, M_DONTWAIT))) {
+ if (!(freeme = malloc(i, M_PFKEY, M_DONTWAIT | M_ZERO))) {
rval = ENOMEM;
goto ret;
}
- bzero(freeme, i);
-
ssup = (struct sadb_supported *) freeme;
ssup->sadb_supported_len = i / sizeof(uint64_t);
@@ -1687,8 +1675,8 @@ pfkeyv2_send(struct socket *socket, void *message, int len)
int clen = (sid->sadb_ident_len * sizeof(u_int64_t)) -
sizeof(struct sadb_ident);
- MALLOC(ipo->ipo_srcid, struct ipsec_ref *, clen +
- sizeof(struct ipsec_ref), M_CREDENTIALS, M_DONTWAIT);
+ ipo->ipo_srcid = malloc(clen + sizeof(struct ipsec_ref),
+ M_CREDENTIALS, M_DONTWAIT);
if (ipo->ipo_srcid == NULL) {
if (exists)
ipsec_delete_policy(ipo);
@@ -1709,8 +1697,7 @@ pfkeyv2_send(struct socket *socket, void *message, int len)
int clen = (sid->sadb_ident_len * sizeof(u_int64_t)) -
sizeof(struct sadb_ident);
- MALLOC(ipo->ipo_dstid, struct ipsec_ref *,
- clen + sizeof(struct ipsec_ref),
+ ipo->ipo_dstid = malloc(clen + sizeof(struct ipsec_ref),
M_CREDENTIALS, M_DONTWAIT);
if (ipo->ipo_dstid == NULL) {
if (exists)
@@ -1896,7 +1883,7 @@ pfkeyv2_acquire(struct ipsec_policy *ipo, union sockaddr_union *gw,
i += sizeof(struct sadb_x_cred) + PADUP(ipo->ipo_local_auth->ref_len);
/* Allocate */
- if (!(p = malloc(i, M_PFKEY, M_DONTWAIT))) {
+ if (!(p = malloc(i, M_PFKEY, M_DONTWAIT | M_ZERO))) {
rval = ENOMEM;
goto ret;
}
@@ -1904,7 +1891,6 @@ pfkeyv2_acquire(struct ipsec_policy *ipo, union sockaddr_union *gw,
bzero(headers, sizeof(headers));
buffer = p;
- bzero(p, i);
headers[0] = p;
p += sizeof(struct sadb_msg);
@@ -2165,7 +2151,7 @@ pfkeyv2_expire(struct tdb *sa, u_int16_t type)
sizeof(struct sadb_address) + PADUP(SA_LEN(&sa->tdb_src.sa)) +
sizeof(struct sadb_address) + PADUP(SA_LEN(&sa->tdb_dst.sa));
- if (!(p = malloc(i, M_PFKEY, M_DONTWAIT))) {
+ if (!(p = malloc(i, M_PFKEY, M_DONTWAIT | M_ZERO))) {
rval = ENOMEM;
goto ret;
}
@@ -2173,7 +2159,6 @@ pfkeyv2_expire(struct tdb *sa, u_int16_t type)
bzero(headers, sizeof(headers));
buffer = p;
- bzero(p, i);
headers[0] = p;
p += sizeof(struct sadb_msg);
@@ -2360,13 +2345,11 @@ pfkeyv2_dump_policy(struct ipsec_policy *ipo, void **headers, void **buffer,
goto ret;
}
- if (!(p = malloc(i, M_PFKEY, M_DONTWAIT))) {
+ if (!(p = malloc(i, M_PFKEY, M_DONTWAIT | M_ZERO))) {
rval = ENOMEM;
goto ret;
- } else {
+ } else
*buffer = p;
- bzero(p, i);
- }
/* Local address. */
if (ipo->ipo_src.sa.sa_family) {
diff --git a/sys/net/pfkeyv2_convert.c b/sys/net/pfkeyv2_convert.c
index baa61c0a90e..c39d86fc9e6 100644
--- a/sys/net/pfkeyv2_convert.c
+++ b/sys/net/pfkeyv2_convert.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkeyv2_convert.c,v 1.29 2006/11/24 13:52:14 reyk Exp $ */
+/* $OpenBSD: pfkeyv2_convert.c,v 1.30 2007/09/13 21:00:14 hshoexer Exp $ */
/*
* The author of this code is Angelos D. Keromytis (angelos@keromytis.org)
*
@@ -727,9 +727,8 @@ import_auth(struct tdb *tdb, struct sadb_x_cred *sadb_auth, int dstauth)
else
ipr = &tdb->tdb_local_auth;
- MALLOC(*ipr, struct ipsec_ref *, EXTLEN(sadb_auth) -
- sizeof(struct sadb_x_cred) + sizeof(struct ipsec_ref),
- M_CREDENTIALS, M_WAITOK);
+ *ipr = malloc(EXTLEN(sadb_auth) - sizeof(struct sadb_x_cred) +
+ sizeof(struct ipsec_ref), M_CREDENTIALS, M_WAITOK);
(*ipr)->ref_len = EXTLEN(sadb_auth) - sizeof(struct sadb_x_cred);
switch (sadb_auth->sadb_x_cred_type) {
@@ -740,7 +739,7 @@ import_auth(struct tdb *tdb, struct sadb_x_cred *sadb_auth, int dstauth)
(*ipr)->ref_type = IPSP_AUTH_RSA;
break;
default:
- FREE(*ipr, M_CREDENTIALS);
+ free(*ipr, M_CREDENTIALS);
*ipr = NULL;
return;
}
@@ -766,9 +765,8 @@ import_credentials(struct tdb *tdb, struct sadb_x_cred *sadb_cred, int dstcred)
else
ipr = &tdb->tdb_local_cred;
- MALLOC(*ipr, struct ipsec_ref *, EXTLEN(sadb_cred) -
- sizeof(struct sadb_x_cred) + sizeof(struct ipsec_ref),
- M_CREDENTIALS, M_WAITOK);
+ *ipr = malloc(EXTLEN(sadb_cred) - sizeof(struct sadb_x_cred) +
+ sizeof(struct ipsec_ref), M_CREDENTIALS, M_WAITOK);
(*ipr)->ref_len = EXTLEN(sadb_cred) - sizeof(struct sadb_x_cred);
switch (sadb_cred->sadb_x_cred_type) {
@@ -779,7 +777,7 @@ import_credentials(struct tdb *tdb, struct sadb_x_cred *sadb_cred, int dstcred)
(*ipr)->ref_type = IPSP_CRED_KEYNOTE;
break;
default:
- FREE(*ipr, M_CREDENTIALS);
+ free(*ipr, M_CREDENTIALS);
*ipr = NULL;
return;
}
@@ -805,9 +803,8 @@ import_identity(struct tdb *tdb, struct sadb_ident *sadb_ident, int type)
else
ipr = &tdb->tdb_dstid;
- MALLOC(*ipr, struct ipsec_ref *, EXTLEN(sadb_ident) -
- sizeof(struct sadb_ident) + sizeof(struct ipsec_ref),
- M_CREDENTIALS, M_WAITOK);
+ *ipr = malloc(EXTLEN(sadb_ident) - sizeof(struct sadb_ident) +
+ sizeof(struct ipsec_ref), M_CREDENTIALS, M_WAITOK);
(*ipr)->ref_len = EXTLEN(sadb_ident) - sizeof(struct sadb_ident);
switch (sadb_ident->sadb_ident_type) {
@@ -824,7 +821,7 @@ import_identity(struct tdb *tdb, struct sadb_ident *sadb_ident, int type)
(*ipr)->ref_type = IPSP_IDENTITY_CONNECTION;
break;
default:
- FREE(*ipr, M_CREDENTIALS);
+ free(*ipr, M_CREDENTIALS);
*ipr = NULL;
return;
}