From f86df5580e86c2405c71c708408eeee57b38c0d3 Mon Sep 17 00:00:00 2001 From: Stephen Hines Date: Mon, 17 Aug 2015 17:16:59 -0700 Subject: [PATCH] Move local union such that it doesn't escape (and get optimized out). Bug: 23239997 The Clang update exposed a latent bug in the code here, where a pointer to a local variable escaped the encapsulating block. Clang noticed the end of this object's lifetime, and removed assignments to its original storage (because they are now dead assignments). By moving the union out of the block, it will survive until the sendmsg() call, and the expected writes will be restored. Change-Id: If2106d2f53d761ddca6dd26ab2648244d737dcd9 --- client/FwmarkClient.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/FwmarkClient.cpp b/client/FwmarkClient.cpp index 5074a78..a82f4c2 100644 --- a/client/FwmarkClient.cpp +++ b/client/FwmarkClient.cpp @@ -66,12 +66,12 @@ int FwmarkClient::send(FwmarkCommand* data, int fd) { message.msg_iov = &iov; message.msg_iovlen = 1; - if (data->cmdId != FwmarkCommand::QUERY_USER_ACCESS) { - union { - cmsghdr cmh; - char cmsg[CMSG_SPACE(sizeof(fd))]; - } cmsgu; + union { + cmsghdr cmh; + char cmsg[CMSG_SPACE(sizeof(fd))]; + } cmsgu; + if (data->cmdId != FwmarkCommand::QUERY_USER_ACCESS) { memset(cmsgu.cmsg, 0, sizeof(cmsgu.cmsg)); message.msg_control = cmsgu.cmsg; message.msg_controllen = sizeof(cmsgu.cmsg); -- 2.11.0