r3708: BUG 1838: patch from Gavrie Philipson <gavrie@disksites.com> to remove stale...
[ira/wip.git] / source / lib / wins_srv.c
index 328350f2be7f4eb45522bbb6986540bf7366e5be..4a54762fde74578d2432d44b6a77c7b87eb13052 100644 (file)
 #define DEATH_TIME 600
 
 /* The list of dead wins servers is stored in gencache.tdb.  Each server is
-   marked dead m the point of view of a given source address. We keep a 
+   marked dead from the point of view of a given source address. We keep a 
    separate dead list for each src address to cope with multiple interfaces 
    that are not routable to each other.
   */
 
 #define WINS_SRV_FMT "WINS_SRV_DEAD/%s,%s" /* wins_ip,src_ip */
 
-/*
-  see if an ip is on the dead list
-*/
-
 static char *wins_srv_keystr(struct in_addr wins_ip, struct in_addr src_ip)
 {
-       char *keystr;
+       char *keystr = NULL, *wins_ip_addr = NULL, *src_ip_addr = NULL;
 
-       if (asprintf(&keystr, WINS_SRV_FMT, inet_ntoa(wins_ip),
-                    inet_ntoa(src_ip)) == -1) {
-               DEBUG(0, ("wins_srv_is_dead: malloc error\n"));
-               return NULL;
+       wins_ip_addr = strdup(inet_ntoa(wins_ip));
+       src_ip_addr = strdup(inet_ntoa(src_ip));
+
+       if ( !wins_ip_addr || !src_ip_addr ) {
+               DEBUG(0,("wins_srv_keystr: malloc error\n"));
+               goto done;
        }
 
+       if (asprintf(&keystr, WINS_SRV_FMT, wins_ip_addr, src_ip_addr) == -1) {
+               DEBUG(0, (": ns_srv_keystr: malloc error for key string\n"));
+       }
+
+done:
+       SAFE_FREE(wins_ip_addr);
+       SAFE_FREE(src_ip_addr);
+
        return keystr;
 }
 
+/*
+  see if an ip is on the dead list
+*/
+
 BOOL wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip)
 {
        char *keystr = wins_srv_keystr(wins_ip, src_ip);