This reverts commit
49587447b55d63cd1e97ce4a70011e2a512ead98.
There is only when ip_options_get() return zero need to free.
It already called kfree() when return error.
Fixes: 49587447b55d ("ipv4: fix memory leaks in ip_cmsg_send() callers")
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
Signed-off-by: David S. Miller <davem@davemloft.net>
case IP_RETOPTS:
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,
KERNEL_SOCKPTR(CMSG_DATA(cmsg)),
err < 40 ? err : 40);
if (msg->msg_controllen) {
err = ip_cmsg_send(sk, msg, &ipc, false);
- if (unlikely(err)) {
- kfree(ipc.opt);
+ if (unlikely(err))
return err;
- }
+
if (ipc.opt)
free = 1;
}
if (msg->msg_controllen) {
err = ip_cmsg_send(sk, msg, &ipc, false);
- if (unlikely(err)) {
- kfree(ipc.opt);
+ if (unlikely(err))
goto out;
- }
+
if (ipc.opt)
free = 1;
}
if (err > 0)
err = ip_cmsg_send(sk, msg, &ipc,
sk->sk_family == AF_INET6);
- if (unlikely(err < 0)) {
- kfree(ipc.opt);
+ if (unlikely(err < 0))
return err;
- }
+
if (ipc.opt)
free = 1;
connected = 0;