Make names of c-ares callbacks unique.
authorZdeněk Salvet <salvet@ics.muni.cz>
Fri, 19 Mar 2010 10:26:18 +0000 (10:26 +0000)
committerZdeněk Salvet <salvet@ics.muni.cz>
Fri, 19 Mar 2010 10:26:18 +0000 (10:26 +0000)
Fix position of ares_destroy calls.

org.glite.lb.server/src/bkserverd.c
org.glite.security.gss/src/glite_gss.c

index 2ca1f66..5e60f2d 100644 (file)
@@ -1738,6 +1738,7 @@ static int wait_for_open(edg_wll_Context ctx, const char *dbstring)
        return err;
 }
 
+#if 0
 static void free_hostent(struct hostent *h){
        int i;
 
@@ -1754,6 +1755,7 @@ static void free_hostent(struct hostent *h){
                free(h);
        }
 }
+#endif
 
 struct asyn_result {
        char            *host;
@@ -1762,7 +1764,11 @@ struct asyn_result {
 };
 
 /* ares callback handler for ares_getnameinfo() */
-void callback_handler(void *arg, int status, char *node, char *service)
+#if ARES_VERSION >= 0x010500
+void callback_ares_getnameinfo(void *arg, int status, int timeouts, char *node, char *service)
+#else
+void callback_ares_getnameinfo(void *arg, int status, char *node, char *service)
+#endif
 {
        struct asyn_result *arp = (struct asyn_result *) arg;
 
@@ -1804,6 +1810,7 @@ static int asyn_gethostbyaddr(char **name, char **service, const struct sockaddr
        struct timeval tv, *tvp;
        struct timeval start_time,check_time;
        int     flags = 0;
+       int     err = NETDB_INTERNAL;
 
 /* start timer */
         gettimeofday(&start_time,0);
@@ -1815,7 +1822,7 @@ static int asyn_gethostbyaddr(char **name, char **service, const struct sockaddr
 /* query DNS server asynchronously */
        if (name) flags |= ARES_NI_LOOKUPHOST | ( numeric? ARES_NI_NUMERICHOST : 0);
        if (service) flags |= ARES_NI_LOOKUPSERVICE | ( numeric? ARES_NI_NUMERICSERV : 0);
-       ares_getnameinfo(channel, addr, len, flags, (ares_nameinfo_callback)callback_handler, (void *) &ar);
+       ares_getnameinfo(channel, addr, len, flags, (ares_nameinfo_callback)callback_ares_getnameinfo, (void *) &ar);
 
 /* wait for result */
         while (1) {
@@ -1849,14 +1856,14 @@ static int asyn_gethostbyaddr(char **name, char **service, const struct sockaddr
 
         }
 
-       
-       ares_destroy(channel);
-               
        if (ar.err == NETDB_SUCCESS) {
                if (name) *name = ar.host;
                if (service) *service = ar.service;
        }
-       return (ar.err);
+       err = ar.err;
+
+       ares_destroy(channel);
+       return err;
 }
 
 static int add_root(edg_wll_Context ctx, char *root)
index 02a2611..ead8b74 100644 (file)
@@ -73,9 +73,9 @@ static int decrement_timeout(struct timeval *timeout, struct timeval before, str
 
 /* ares callback handler for ares_gethostbyname()       */
 #if ARES_VERSION >= 0x010500
-static void callback_handler(void *arg, int status, int timeouts, struct hostent *h)
+static void callback_ares_gethostbyname(void *arg, int status, int timeouts, struct hostent *h)
 #else
-static void callback_handler(void *arg, int status, struct hostent *h)
+static void callback_ares_gethostbyname(void *arg, int status, struct hostent *h)
 #endif
 {
        struct asyn_result *arp = (struct asyn_result *) arg;
@@ -144,6 +144,7 @@ static int asyn_getservbyname(struct sockaddr_storage *addrOut, socklen_t *a_len
        fd_set readers, writers;
        struct timeval tv, *tvp;
        struct timeval start_time,check_time;
+       int     err = NETDB_INTERNAL;
 
 /* start timer */
        gettimeofday(&start_time,0);
@@ -153,7 +154,7 @@ static int asyn_getservbyname(struct sockaddr_storage *addrOut, socklen_t *a_len
        ar.ent = (struct hostent *) calloc (sizeof(*ar.ent),1);
 
 /* query DNS server asynchronously */
-       ares_gethostbyname(channel, name, AF_INET6, callback_handler,
+       ares_gethostbyname(channel, name, AF_INET6, callback_ares_gethostbyname,
                           (void *) &ar);
 
 /* wait for result */
@@ -189,8 +190,6 @@ static int asyn_getservbyname(struct sockaddr_storage *addrOut, socklen_t *a_len
                }
        }
 
-       ares_destroy(channel);
-
        if (ar.err == NETDB_SUCCESS) {
                struct sockaddr_in *p4 = (struct sockaddr_in *)addrOut;
                struct sockaddr_in6 *p6 = (struct sockaddr_in6 *)addrOut;
@@ -213,9 +212,12 @@ static int asyn_getservbyname(struct sockaddr_storage *addrOut, socklen_t *a_len
                                break;
                }
        }
+       free_hostent(ar.ent); ar.ent = NULL;
+       err = ar.err;
+
+       ares_destroy(channel);
 
-       free_hostent(ar.ent);
-       return(ar.err);
+       return err;
 }
 
 static int