1
0
mirror of https://github.com/gluster/gluster-block.git synced 2026-02-05 12:45:33 +01:00

rpc: avoid socket double free

From man:

clnt_destroy(CLIENT *clnt);
 A macro that destroys the client's RPC handle.  Destruction usually involves
 deallocation of  private data  structures,  including clnt itself.  Use of
 clnt is undefined after calling clnt_destroy(). If the RPC library opened the
 associated socket, it will close it also. Otherwise, the socket remains open.

we are closing the socket twice in this case,
i.e. by calling clnt_destroy and then close(sockfd)

Thanks to Pranith for the RC.

Tested-by: Xiubo Li <xiubli@redhat.com>
Reviewed-by: Xiubo Li <xiubli@redhat.com>
Reviewed-by: Pranith Kumar K <pkarampu@redhat.com>
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever
2018-07-12 23:15:02 +05:30
committed by Prasanna Kumar Kalever
parent 32ee76655d
commit 766f97ed8a
3 changed files with 9 additions and 13 deletions

View File

@@ -59,7 +59,7 @@ glusterBlockCliRPC_1(void *cobj, clioperations opt)
{
CLIENT *clnt = NULL;
int ret = -1;
int sockfd = -1;
int sockfd = RPC_ANYSOCK;
struct sockaddr_un saun = {0,};
blockCreateCli *create_obj;
blockDeleteCli *delete_obj;
@@ -204,7 +204,7 @@ glusterBlockCliRPC_1(void *cobj, clioperations opt)
clnt_destroy (clnt);
}
if (sockfd != -1) {
if (sockfd != RPC_ANYSOCK) {
close (sockfd);
}

View File

@@ -61,7 +61,7 @@ glusterBlockCliThreadProc (void *vargp)
{
register SVCXPRT *transp = NULL;
struct sockaddr_un saun = {0, };
int sockfd = -1;
int sockfd = RPC_ANYSOCK;
if (strlen(GB_UNIX_ADDRESS) > SUN_PATH_MAX) {
@@ -116,7 +116,7 @@ glusterBlockCliThreadProc (void *vargp)
svc_destroy(transp);
}
if (sockfd != -1) {
if (sockfd != RPC_ANYSOCK) {
close(sockfd);
}
@@ -129,7 +129,7 @@ glusterBlockServerThreadProc(void *vargp)
{
register SVCXPRT *transp = NULL;
struct sockaddr_in sain = {0, };
int sockfd;
int sockfd = RPC_ANYSOCK;
int opt = 1;
char errMsg[2048] = {0};
@@ -177,7 +177,7 @@ glusterBlockServerThreadProc(void *vargp)
svc_destroy(transp);
}
if (sockfd != -1) {
if (sockfd != RPC_ANYSOCK) {
close(sockfd);
}

View File

@@ -485,7 +485,7 @@ glusterBlockGetSockaddr(char *host)
static int glusterBlockHostConnect(char *host)
{
int sockfd = -1;
int sockfd = RPC_ANYSOCK;
int errsv = 0;
struct addrinfo *res = NULL;
@@ -522,7 +522,7 @@ out:
freeaddrinfo(res);
}
if (sockfd != -1) {
if (sockfd != RPC_ANYSOCK) {
close(sockfd);
}
@@ -560,7 +560,7 @@ glusterBlockCallRPC_1(char *host, void *cobj,
{
CLIENT *clnt = NULL;
int ret = -1;
int sockfd = -1;
int sockfd = RPC_ANYSOCK;
int errsv = 0;
size_t i;
blockResponse reply = {0,};
@@ -690,10 +690,6 @@ glusterBlockCallRPC_1(char *host, void *cobj,
freeaddrinfo(res);
}
if (sockfd != -1) {
close(sockfd);
}
if (errsv) {
errno = errsv;
}