nwrap: fix a copy and paste error in the destructor.
[obnox/samba/samba-obnox.git] / lib / nss_wrapper / nss_wrapper.c
index d204ea60a8f31de6b6ee3908819efc88387d115f..a6ca81637ffe3dda29b361a6855a5da37f5afe3c 100644 (file)
@@ -770,8 +770,8 @@ struct nwrap_entlist {
 struct nwrap_he {
        struct nwrap_cache *cache;
 
-       struct nwrap_entdata *list;
-       struct nwrap_vector entdata;
+       struct nwrap_vector entries;
+       struct nwrap_vector lists;
 
        int num;
        int idx;
@@ -2576,6 +2576,7 @@ static bool nwrap_ed_inventarize_add_new(char *const h_name,
        ENTRY e;
        ENTRY *p;
        struct nwrap_entlist *el;
+       bool ok;
 
        if (h_name == NULL) {
                NWRAP_LOG(NWRAP_LOG_ERROR, "h_name NULL - can't add");
@@ -2596,6 +2597,13 @@ static bool nwrap_ed_inventarize_add_new(char *const h_name,
                return false;
        }
 
+       ok = nwrap_vector_add_item(&(nwrap_he_global.lists), (void *)el);
+       if (!ok) {
+               NWRAP_LOG(NWRAP_LOG_ERROR,
+                         "Failed to add list entry to vector.");
+               return false;
+       }
+
        return true;
 }
 
@@ -2758,8 +2766,13 @@ static bool nwrap_he_parse_line(struct nwrap_cache *nwrap, char *line)
        }
        ip = i;
 
-       nwrap_vector_add_item(&(ed->nwrap_addrdata),
-                             (void *const)ed->addr.host_addr);
+       ok = nwrap_vector_add_item(&(ed->nwrap_addrdata),
+                                  (void *const)ed->addr.host_addr);
+       if (!ok) {
+               NWRAP_LOG(NWRAP_LOG_ERROR, "Unable to add addrdata to vector");
+               free(ed);
+               return false;
+       }
        ed->ht.h_addr_list = nwrap_vector_head(&ed->nwrap_addrdata);
 
        p++;
@@ -2845,7 +2858,12 @@ static bool nwrap_he_parse_line(struct nwrap_cache *nwrap, char *line)
                aliases_count += 1;
        }
 
-       nwrap_vector_add_item(&(nwrap_he->entdata), (void *const)ed);
+       ok = nwrap_vector_add_item(&(nwrap_he->entries), (void *const)ed);
+       if (!ok) {
+               NWRAP_LOG(NWRAP_LOG_ERROR, "Unable to add entry to vector");
+               free(ed);
+               return false;
+       }
 
        ed->aliases_count = aliases_count;
        /* Inventarize item */
@@ -2868,16 +2886,30 @@ static void nwrap_he_unload(struct nwrap_cache *nwrap)
        struct nwrap_he *nwrap_he =
                (struct nwrap_he *)nwrap->private_data;
        struct nwrap_entdata *ed;
+       struct nwrap_entlist *el;
        size_t i;
 
-       nwrap_vector_foreach (ed, nwrap_he->entdata, i)
+       nwrap_vector_foreach (ed, nwrap_he->entries, i)
        {
                SAFE_FREE(ed->nwrap_addrdata.items);
                SAFE_FREE(ed->ht.h_aliases);
                SAFE_FREE(ed);
        }
-       SAFE_FREE(nwrap_he->entdata.items);
-       nwrap_he->entdata.count = nwrap_he->entdata.capacity = 0;
+       SAFE_FREE(nwrap_he->entries.items);
+       nwrap_he->entries.count = nwrap_he->entries.capacity = 0;
+
+       nwrap_vector_foreach(el, nwrap_he->lists, i)
+       {
+               while (el != NULL) {
+                       struct nwrap_entlist *el_next;
+
+                       el_next = el->next;
+                       SAFE_FREE(el);
+                       el = el_next;
+               }
+       }
+       SAFE_FREE(nwrap_he->lists.items);
+       nwrap_he->lists.count = nwrap_he->lists.capacity = 0;
 
        nwrap_he->num = 0;
        nwrap_he->idx = 0;
@@ -3631,7 +3663,7 @@ static struct hostent *nwrap_files_gethostbyaddr(const void *addr,
                return NULL;
        }
 
-       nwrap_vector_foreach(ed, nwrap_he_global.entdata, i)
+       nwrap_vector_foreach(ed, nwrap_he_global.entries, i)
        {
                he = &(ed->ht);
                if (he->h_addrtype != type) {
@@ -3709,7 +3741,7 @@ static struct hostent *nwrap_files_gethostent(void)
                return NULL;
        }
 
-       he = &((struct nwrap_entdata *)nwrap_he_global.entdata.items[nwrap_he_global.idx++])->ht;
+       he = &((struct nwrap_entdata *)nwrap_he_global.entries.items[nwrap_he_global.idx++])->ht;
 
        NWRAP_LOG(NWRAP_LOG_DEBUG, "return hosts[%s]", he->h_name);
 
@@ -5519,6 +5551,18 @@ void nwrap_destructor(void)
                nwrap_pw_global.num = 0;
        }
 
+       if (nwrap_sp_global.cache != NULL) {
+               struct nwrap_cache *c = nwrap_sp_global.cache;
+
+               nwrap_files_cache_unload(c);
+               if (c->fd >= 0) {
+                       fclose(c->fp);
+                       c->fd = -1;
+               }
+
+               nwrap_sp_global.num = 0;
+       }
+
        if (nwrap_he_global.cache != NULL) {
                struct nwrap_cache *c = nwrap_he_global.cache;