summaryrefslogtreecommitdiff
path: root/net/l2tpv3.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2014-12-04 14:28:17 +0100
committerStefan Hajnoczi <stefanha@redhat.com>2014-12-19 13:17:02 +0000
commit58889fe50a7c5b8776cf3096a8fe611fb66c4e5c (patch)
treec5cf3f17b67b4cfe5573942b02b78a7435d86dfe /net/l2tpv3.c
parent71e28e3cc24ff3b0268903758aae357592eb8b74 (diff)
downloadqemu-58889fe50a7c5b8776cf3096a8fe611fb66c4e5c.tar.gz
net: Use g_new() & friends where that makes obvious sense
g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowing size_t. Two, it returns T * rather than void *, which lets the compiler catch more type errors. This commit only touches allocations with size arguments of the form sizeof(T). Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'net/l2tpv3.c')
-rw-r--r--net/l2tpv3.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/net/l2tpv3.c b/net/l2tpv3.c
index 6014c43eff..8c598b09bc 100644
--- a/net/l2tpv3.c
+++ b/net/l2tpv3.c
@@ -489,12 +489,12 @@ static struct mmsghdr *build_l2tpv3_vector(NetL2TPV3State *s, int count)
struct iovec *iov;
struct mmsghdr *msgvec, *result;
- msgvec = g_malloc(sizeof(struct mmsghdr) * count);
+ msgvec = g_new(struct mmsghdr, count);
result = msgvec;
for (i = 0; i < count ; i++) {
msgvec->msg_hdr.msg_name = NULL;
msgvec->msg_hdr.msg_namelen = 0;
- iov = g_malloc(sizeof(struct iovec) * IOVSIZE);
+ iov = g_new(struct iovec, IOVSIZE);
msgvec->msg_hdr.msg_iov = iov;
iov->iov_base = g_malloc(s->header_size);
iov->iov_len = s->header_size;
@@ -729,7 +729,7 @@ int net_init_l2tpv3(const NetClientOptions *opts,
}
s->msgvec = build_l2tpv3_vector(s, MAX_L2TPV3_MSGCNT);
- s->vec = g_malloc(sizeof(struct iovec) * MAX_L2TPV3_IOVCNT);
+ s->vec = g_new(struct iovec, MAX_L2TPV3_IOVCNT);
s->header_buf = g_malloc(s->header_size);
qemu_set_nonblock(fd);