diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 12db1a0dd5ab..1c53db647aff 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -1155,7 +1155,8 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, if (msg->msg_name) { sa = malloc(msg->msg_namelen, M_SONAME, M_WAITOK); msg->msg_name = sa; - } + } else + sa = NULL; uiov = msg->msg_iov; msg->msg_iov = iov; @@ -1172,7 +1173,6 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, error = copyout(lsa, PTRIN(msg->msg_name), msg->msg_namelen); free(lsa, M_SONAME); - free(sa, M_SONAME); if (error != 0) goto bad; } @@ -1292,6 +1292,7 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, } free(iov, M_IOV); free(linux_cmsg, M_LINUX); + free(sa, M_SONAME); return (error); }