nwrap: fix leaking the entlists
authorMichael Adam <obnox@samba.org>
Thu, 19 Nov 2015 00:00:16 +0000 (01:00 +0100)
committerMichael Adam <obnox@samba.org>
Mon, 11 Jan 2016 11:25:32 +0000 (12:25 +0100)
Track the list heads in a vector in the newrap_he_global
struct and free the structures upon nwrap_he_unload.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/nss_wrapper/nss_wrapper.c

index f7979decfae2e230a869d4c3e7e03e83b9524930..562efba251509114fab02304579957f96c005381 100644 (file)
@@ -771,6 +771,7 @@ struct nwrap_he {
        struct nwrap_cache *cache;
 
        struct nwrap_vector entries;
+       struct nwrap_vector lists;
 
        int num;
        int idx;
@@ -2575,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");
@@ -2595,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;
 }
 
@@ -2877,6 +2886,7 @@ 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->entries, i)
@@ -2888,6 +2898,19 @@ static void nwrap_he_unload(struct nwrap_cache *nwrap)
        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;
 }