af_unix: use __do_free

parent d85617bc
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "config.h" #include "config.h"
#include "log.h" #include "log.h"
#include "memory_utils.h"
#include "raw_syscalls.h" #include "raw_syscalls.h"
#include "utils.h" #include "utils.h"
...@@ -155,12 +156,11 @@ int lxc_abstract_unix_connect(const char *path) ...@@ -155,12 +156,11 @@ int lxc_abstract_unix_connect(const char *path)
int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds, int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds,
void *data, size_t size) void *data, size_t size)
{ {
int ret; __do_free char *cmsgbuf;
struct msghdr msg; struct msghdr msg;
struct iovec iov; struct iovec iov;
struct cmsghdr *cmsg = NULL; struct cmsghdr *cmsg = NULL;
char buf[1] = {0}; char buf[1] = {0};
char *cmsgbuf;
size_t cmsgbufsize = CMSG_SPACE(num_sendfds * sizeof(int)); size_t cmsgbufsize = CMSG_SPACE(num_sendfds * sizeof(int));
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
...@@ -189,20 +189,18 @@ int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds, ...@@ -189,20 +189,18 @@ int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds,
msg.msg_iov = &iov; msg.msg_iov = &iov;
msg.msg_iovlen = 1; msg.msg_iovlen = 1;
ret = sendmsg(fd, &msg, MSG_NOSIGNAL); return sendmsg(fd, &msg, MSG_NOSIGNAL);
free(cmsgbuf);
return ret;
} }
int lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds, int lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds,
void *data, size_t size) void *data, size_t size)
{ {
__do_free char *cmsgbuf;
int ret; int ret;
struct msghdr msg; struct msghdr msg;
struct iovec iov; struct iovec iov;
struct cmsghdr *cmsg = NULL; struct cmsghdr *cmsg = NULL;
char buf[1] = {0}; char buf[1] = {0};
char *cmsgbuf;
size_t cmsgbufsize = CMSG_SPACE(num_recvfds * sizeof(int)); size_t cmsgbufsize = CMSG_SPACE(num_recvfds * sizeof(int));
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
...@@ -234,7 +232,6 @@ int lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds, ...@@ -234,7 +232,6 @@ int lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds,
memcpy(recvfds, CMSG_DATA(cmsg), num_recvfds * sizeof(int)); memcpy(recvfds, CMSG_DATA(cmsg), num_recvfds * sizeof(int));
out: out:
free(cmsgbuf);
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment