diff options
author | Vic Lee <llyzs@163.com> | 2010-05-30 23:20:55 +0800 |
---|---|---|
committer | Vic Lee <llyzs@163.com> | 2010-05-30 23:20:55 +0800 |
commit | 95184bd1d4b83dccee5455ab324b724b6b90dea9 (patch) | |
tree | 8f78956d50d87fa6ec063dcb22baf5efb30668f3 | |
parent | 8a7e0fe8dea1d453ec84281527a3d13e1269492d (diff) |
Fix some memory leaks
-rw-r--r-- | xdmcpclient.c | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/xdmcpclient.c b/xdmcpclient.c index b3d8eae..e22ccb7 100644 --- a/xdmcpclient.c +++ b/xdmcpclient.c @@ -100,8 +100,8 @@ struct _XdmcpClient int Sock; int Timeout; - XdmcpHeader header; - XdmcpBuffer buffer; + XdmcpHeader header; + XdmcpBuffer buffer; ARRAYofARRAY8 AuthenNames; ARRAYofARRAY8 AuthenDatas; @@ -184,6 +184,7 @@ XdmcpClientRegisterServer (XdmcpClient *client, const char *host, const char *po { struct addrinfo hints; struct addrinfo *res; + struct addrinfo *resi; int error; int sock; @@ -195,25 +196,23 @@ XdmcpClientRegisterServer (XdmcpClient *client, const char *host, const char *po printf ("Error> getaddrinfo on %s:%s failed: %s.\n", host, port, gai_strerror (error)); return FALSE; } - while (res) + for (resi = res; resi; resi = resi->ai_next) { - /* TODO: Somehow gdm does not response on IPv6? will figure it out later */ - if (res->ai_family == AF_INET || res->ai_family == AF_INET6) + if (resi->ai_family == AF_INET || resi->ai_family == AF_INET6) { - break; + break; } - res = res->ai_next; - } - if (res == NULL) + } + if (resi == NULL) { printf ("Error> host not on supported network type.\n"); return FALSE; } - memmove (&client->Addr, res->ai_addr, res->ai_addrlen); - client->AddrLen = res->ai_addrlen; + memmove (&client->Addr, resi->ai_addr, resi->ai_addrlen); + client->AddrLen = resi->ai_addrlen; - sock = socket (res->ai_family, SOCK_DGRAM, 0); + sock = socket (resi->ai_family, SOCK_DGRAM, 0); if (sock < 0) { printf ("Error> failed to create socket.\n"); @@ -221,6 +220,8 @@ XdmcpClientRegisterServer (XdmcpClient *client, const char *host, const char *po } client->Sock = sock; + freeaddrinfo (res); + printf ("Client> Server address %s:%s registered.\n", host, port); return TRUE; @@ -258,6 +259,12 @@ XdmcpClientFree (XdmcpClient *client) XdmcpDisposeARRAYofARRAY8 (&client->AuthenNames); XdmcpDisposeARRAYofARRAY8 (&client->AuthenDatas); XdmcpDisposeARRAYofARRAY8 (&client->AuthorNames); + XdmcpDisposeARRAY8 (&client->AuthorName); + XdmcpDisposeARRAY8 (&client->AuthorData); + XdmcpDisposeARRAY8 (&client->DisplayClass); + XdmcpDisposeARRAY8 (&client->DisplayID); + if (client->buffer.data) + Xfree (client->buffer.data); free (client); } @@ -301,12 +308,12 @@ XdmcpClientReceivePacket (XdmcpClient *client) if (!XdmcpReadHeader (&client->buffer, &client->header)) { printf ("Error> Received corrupted packet header.\n"); - return FALSE; + return FALSE; } if (client->header.version != XDM_PROTOCOL_VERSION) { printf ("Error> Received unsupported version %i.\n", client->header.version); - return FALSE; + return FALSE; } return TRUE; } |