diff options
| author | Volker Lendecke <vl@samba.org> | 2014-07-24 14:59:33 +0000 |
|---|---|---|
| committer | Jeremy Allison <jra@samba.org> | 2014-07-28 22:04:13 +0200 |
| commit | f4e7a49cd755532a4201311655f3474228fd7b81 (patch) | |
| tree | cda385627c3c0da16cd7639def3292f5f4de303c /source3/lib | |
| parent | f1f43886f02966e3fe759d7406b84e46b38867fe (diff) | |
| download | samba-f4e7a49cd755532a4201311655f3474228fd7b81.tar.gz samba-f4e7a49cd755532a4201311655f3474228fd7b81.tar.xz samba-f4e7a49cd755532a4201311655f3474228fd7b81.zip | |
unix_msg: simplify unix_msg_send
We have a variable array inside one-fragment fast path anyway. Moving
that to the toplevel of the function saves us a malloc/free pair.
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/lib')
| -rw-r--r-- | source3/lib/unix_msg/unix_msg.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/source3/lib/unix_msg/unix_msg.c b/source3/lib/unix_msg/unix_msg.c index 2da8b6fdf7..00438cebfd 100644 --- a/source3/lib/unix_msg/unix_msg.c +++ b/source3/lib/unix_msg/unix_msg.c @@ -640,7 +640,7 @@ int unix_msg_send(struct unix_msg_ctx *ctx, const struct sockaddr_un *dst, ssize_t msglen; size_t sent; int ret = 0; - struct iovec *iov_copy; + struct iovec iov_copy[iovlen+2]; struct unix_msg_hdr hdr; struct iovec src_iov; @@ -654,17 +654,16 @@ int unix_msg_send(struct unix_msg_ctx *ctx, const struct sockaddr_un *dst, } if (msglen <= (ctx->fragment_len - sizeof(uint64_t))) { - struct iovec tmp_iov[iovlen+1]; uint64_t cookie = 0; - tmp_iov[0].iov_base = &cookie; - tmp_iov[0].iov_len = sizeof(cookie); + iov_copy[0].iov_base = &cookie; + iov_copy[0].iov_len = sizeof(cookie); if (iovlen > 0) { - memcpy(&tmp_iov[1], iov, + memcpy(&iov_copy[1], iov, sizeof(struct iovec) * iovlen); } - return unix_dgram_send(ctx->dgram, dst, tmp_iov, iovlen+1); + return unix_dgram_send(ctx->dgram, dst, iov_copy, iovlen+1); } hdr = (struct unix_msg_hdr) { @@ -673,10 +672,6 @@ int unix_msg_send(struct unix_msg_ctx *ctx, const struct sockaddr_un *dst, .sock = unix_dgram_sock(ctx->dgram) }; - iov_copy = malloc(sizeof(struct iovec) * (iovlen + 2)); - if (iov_copy == NULL) { - return ENOMEM; - } iov_copy[0].iov_base = &ctx->cookie; iov_copy[0].iov_len = sizeof(ctx->cookie); iov_copy[1].iov_base = &hdr; @@ -730,8 +725,6 @@ int unix_msg_send(struct unix_msg_ctx *ctx, const struct sockaddr_un *dst, } } - free(iov_copy); - ctx->cookie += 1; if (ctx->cookie == 0) { ctx->cookie += 1; |
