From b704638b4291c74db70f6eb0527ccecd37eedd59 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kou=C5=99il?= Date: Thu, 8 Dec 2011 10:51:47 +0000 Subject: [PATCH] handle hostent properly --- emi.canl.canl-c/src/canl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/emi.canl.canl-c/src/canl.c b/emi.canl.canl-c/src/canl.c index c3e069b..145fbf5 100644 --- a/emi.canl.canl-c/src/canl.c +++ b/emi.canl.canl-c/src/canl.c @@ -136,6 +136,9 @@ int canl_io_connect(canl_ctx cc, canl_io_handler io, char * host, int port, return set_error(cc, EINVAL, posix_error, "IO handler not initialized"); /*dns TODO - wrap it for using ipv6 and ipv4 at the same time*/ + ar.ent = (struct hostent *) calloc (1, sizeof(struct hostent)); + if (ar.ent == NULL) + return set_error(cc, ENOMEM, posix_error, "Not enough memory"); switch (err = asyn_getservbyname(AF_INET, &ar, host, NULL)) { case NETDB_SUCCESS: @@ -202,6 +205,9 @@ int canl_io_connect(canl_ctx cc, canl_io_handler io, char * host, int port, err = 0; end: + if (ar.ent != NULL) + free_hostent(ar.ent); + return err; } -- 1.8.2.3