correct memory leak
This commit is contained in:
parent
5ed1869cf0
commit
d630779034
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
/* Connection routines. */
|
/* Connection routines. */
|
||||||
|
|
||||||
/* $Id: connect.c,v 1.24 2005/07/29 16:28:47 kalum Exp $ */
|
/* $Id$ */
|
||||||
|
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -54,16 +54,14 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
|
|||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
error = getaddrinfo(name, szPort, &hints, &res);
|
error = getaddrinfo(name, szPort, &hints, &res);
|
||||||
if (error) {
|
if (error)
|
||||||
freeaddrinfo(res);
|
return HOSTERR;
|
||||||
return HOSTERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Create a socket. */
|
/* Create a socket. */
|
||||||
if ((*sock = socket(res->ai_family, res->ai_socktype, IPPROTO_TCP)) < 1)
|
if ((*sock = socket(res->ai_family, res->ai_socktype, IPPROTO_TCP)) < 1)
|
||||||
{
|
{
|
||||||
free(res);
|
freeaddrinfo(res);
|
||||||
return CONSOCKERR;
|
return CONSOCKERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,11 +108,11 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
|
|||||||
|
|
||||||
if (errno == ECONNREFUSED)
|
if (errno == ECONNREFUSED)
|
||||||
{
|
{
|
||||||
free(res);
|
freeaddrinfo(res);
|
||||||
return CONREFUSED;
|
return CONREFUSED;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
free(res);
|
freeaddrinfo(res);
|
||||||
return CONERROR;
|
return CONERROR;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
@ -133,7 +131,7 @@ uerr_t connect_to_server(int *sock, const char *name, int port,
|
|||||||
setsockopt(*sock, SOL_SOCKET, SO_KEEPALIVE,
|
setsockopt(*sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||||
(char *) &opt, (int) sizeof(opt));
|
(char *) &opt, (int) sizeof(opt));
|
||||||
|
|
||||||
free(res);
|
freeaddrinfo(res);
|
||||||
|
|
||||||
return NOCONERROR;
|
return NOCONERROR;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user