From: Daniel KouĊ™il Date: Thu, 8 Dec 2011 10:51:47 +0000 (+0000) Subject: handle hostent properly X-Git-Tag: merge_30_head_take2_after~18 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=b704638b4291c74db70f6eb0527ccecd37eedd59;p=jra1mw.git handle hostent properly --- 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; }