DLM: fix memory leak in tcp_accept_from_sock()

The sk member of the socket generated by sock_create_kern() is overwritten
by ops->accept(). So the previous sk will not be released.
We use kernel_accept() instead of sock_create_kern() and ops->accept().

Signed-off-by: Tadashi Miyauchi <miyauchi@toshiba-tops.co.jp>
Signed-off-by: Tsutomu Owa <tsutomu.owa@toshiba.co.jp>
Signed-off-by: David Teigland <teigland@redhat.com>
This commit is contained in:
tsutomu.owa@toshiba.co.jp 2017-09-12 09:01:38 +00:00 committed by David Teigland
parent 294e7e4587
commit 3421fb15be

View file

@ -732,22 +732,14 @@ static int tcp_accept_from_sock(struct connection *con)
} }
mutex_unlock(&connections_lock); mutex_unlock(&connections_lock);
memset(&peeraddr, 0, sizeof(peeraddr));
result = sock_create_lite(dlm_local_addr[0]->ss_family,
SOCK_STREAM, IPPROTO_TCP, &newsock);
if (result < 0)
return -ENOMEM;
mutex_lock_nested(&con->sock_mutex, 0); mutex_lock_nested(&con->sock_mutex, 0);
result = -ENOTCONN; if (!con->sock) {
if (con->sock == NULL) mutex_unlock(&con->sock_mutex);
goto accept_err; return -ENOTCONN;
}
newsock->type = con->sock->type; result = kernel_accept(con->sock, &newsock, O_NONBLOCK);
newsock->ops = con->sock->ops;
result = con->sock->ops->accept(con->sock, newsock, O_NONBLOCK, true);
if (result < 0) if (result < 0)
goto accept_err; goto accept_err;
@ -844,7 +836,8 @@ static int tcp_accept_from_sock(struct connection *con)
accept_err: accept_err:
mutex_unlock(&con->sock_mutex); mutex_unlock(&con->sock_mutex);
sock_release(newsock); if (newsock)
sock_release(newsock);
if (result != -EAGAIN) if (result != -EAGAIN)
log_print("error accepting connection from node: %d", result); log_print("error accepting connection from node: %d", result);