On Sunday 05 January 2014 09:59:53 Antonio Quartulli wrote:
+/**
- vlan_get_link_dump - receive and dump a get_link rtnl reply
- @sock: the socket to listen for the reply on
- @buf: pointer to the buffer where the reply has to be dumped to
- @buflen: length of the buffer
- Returns the amount of dumped bytes
- */
+static ssize_t vlan_get_link_dump(int sock, void *buf, size_t buflen) +{
- struct iovec iov;
- struct msghdr msg;
- struct sockaddr_nl nladdr;
- ssize_t ret = -1;
- memset(&msg, 0, sizeof(msg));
- memset(&iov, 0, sizeof(iov));
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
- msg.msg_controllen = 0;
- msg.msg_control = NULL;
- msg.msg_flags = 0;
- msg.msg_name = &nladdr;
- msg.msg_namelen = sizeof(nladdr);
- iov.iov_len = buflen;
- iov.iov_base = buf;
- ret = recvmsg(sock, &msg, 0);
- if (ret < 0)
goto err;
- return ret;
+err:
- free(buf);
- return ret;
+}
Do we double free 'buf' in case of an error ?
+/**
- vlan_get_link_open - send a get_link request
- @ifname: the interface to query
- Returns 0 in case of success or a negative error code otherwise
- */
+static int vlan_get_link_open(const char *ifname) +{
- struct {
struct nlmsghdr hdr;
struct ifinfomsg ifi;
/* attribute has to be NLMAG aligned */
NLMSG aligned ?
Cheers, Marek