From: Volker Lendecke Date: Thu, 24 Jul 2014 14:59:33 +0000 (+0000) Subject: unix_msg: simplify unix_msg_send X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=f4e7a49cd755532a4201311655f3474228fd7b81;p=obnox%2Fsamba%2Fsamba-obnox.git 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 Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/unix_msg/unix_msg.c b/source3/lib/unix_msg/unix_msg.c index 2da8b6fdf74..00438cebfd6 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;