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