Commit d7807a9a authored by Yajun Deng's avatar Yajun Deng Committed by David S. Miller

Revert "ipv4: fix memory leaks in ip_cmsg_send() callers"

This reverts commit 91948309.

There is only when ip_options_get() return zero need to free.
It already called kfree() when return error.

Fixes: 91948309 ("ipv4: fix memory leaks in ip_cmsg_send() callers")
Signed-off-by: default avatarYajun Deng <yajun.deng@linux.dev>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2049eb0d
...@@ -279,7 +279,7 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc, ...@@ -279,7 +279,7 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
case IP_RETOPTS: case IP_RETOPTS:
err = cmsg->cmsg_len - sizeof(struct cmsghdr); err = cmsg->cmsg_len - sizeof(struct cmsghdr);
/* Our caller is responsible for freeing ipc->opt */ /* Our caller is responsible for freeing ipc->opt when err = 0 */
err = ip_options_get(net, &ipc->opt, err = ip_options_get(net, &ipc->opt,
KERNEL_SOCKPTR(CMSG_DATA(cmsg)), KERNEL_SOCKPTR(CMSG_DATA(cmsg)),
err < 40 ? err : 40); err < 40 ? err : 40);
......
...@@ -727,10 +727,9 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -727,10 +727,9 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
if (msg->msg_controllen) { if (msg->msg_controllen) {
err = ip_cmsg_send(sk, msg, &ipc, false); err = ip_cmsg_send(sk, msg, &ipc, false);
if (unlikely(err)) { if (unlikely(err))
kfree(ipc.opt);
return err; return err;
}
if (ipc.opt) if (ipc.opt)
free = 1; free = 1;
} }
......
...@@ -562,10 +562,9 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -562,10 +562,9 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
if (msg->msg_controllen) { if (msg->msg_controllen) {
err = ip_cmsg_send(sk, msg, &ipc, false); err = ip_cmsg_send(sk, msg, &ipc, false);
if (unlikely(err)) { if (unlikely(err))
kfree(ipc.opt);
goto out; goto out;
}
if (ipc.opt) if (ipc.opt)
free = 1; free = 1;
} }
......
...@@ -1122,10 +1122,9 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -1122,10 +1122,9 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
if (err > 0) if (err > 0)
err = ip_cmsg_send(sk, msg, &ipc, err = ip_cmsg_send(sk, msg, &ipc,
sk->sk_family == AF_INET6); sk->sk_family == AF_INET6);
if (unlikely(err < 0)) { if (unlikely(err < 0))
kfree(ipc.opt);
return err; return err;
}
if (ipc.opt) if (ipc.opt)
free = 1; free = 1;
connected = 0; connected = 0;
......
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