void slap_sl_mem_destroy( void *key, void *data ) { struct slab_heap *sh = data; int pad = 2*sizeof(int)-1, pad_shift; int order_start = -1, i; struct slab_object *so; if (sh->sh_stack) { ber_memfree_x(sh->sh_base, NULL); ber_memfree_x(sh, NULL); } else { pad_shift = pad - 1; do { order_start++; } while (pad_shift >>= 1); for (i = 0; i <= sh->sh_maxorder - order_start; i++) { so = LDAP_LIST_FIRST(&sh->sh_free[i]); while (so) { struct slab_object *so_tmp = so; so = LDAP_LIST_NEXT(so, so_link); LDAP_LIST_INSERT_HEAD(&sh->sh_sopool, so_tmp, so_link); } ch_free(sh->sh_map[i]); } ch_free(sh->sh_free); ch_free(sh->sh_map); so = LDAP_LIST_FIRST(&sh->sh_sopool); while (so) { struct slab_object *so_tmp = so; so = LDAP_LIST_NEXT(so, so_link); if (!so_tmp->so_blockhead) { LDAP_LIST_REMOVE(so_tmp, so_link); } } so = LDAP_LIST_FIRST(&sh->sh_sopool); while (so) { struct slab_object *so_tmp = so; so = LDAP_LIST_NEXT(so, so_link); ch_free(so_tmp); } ber_memfree_x(sh->sh_base, NULL); ber_memfree_x(sh, NULL); } }
/* Destroy the context, or if key==NULL clean it up for reuse. */ void slap_sl_mem_destroy( void *key, void *data ) { struct slab_heap *sh = data; struct slab_object *so; int i; if (!sh->sh_stack) { for (i = 0; i <= sh->sh_maxorder - order_start; i++) { so = LDAP_LIST_FIRST(&sh->sh_free[i]); while (so) { struct slab_object *so_tmp = so; so = LDAP_LIST_NEXT(so, so_link); LDAP_LIST_INSERT_HEAD(&sh->sh_sopool, so_tmp, so_link); } ch_free(sh->sh_map[i]); } ch_free(sh->sh_free); ch_free(sh->sh_map); so = LDAP_LIST_FIRST(&sh->sh_sopool); while (so) { struct slab_object *so_tmp = so; so = LDAP_LIST_NEXT(so, so_link); if (!so_tmp->so_blockhead) { LDAP_LIST_REMOVE(so_tmp, so_link); } } so = LDAP_LIST_FIRST(&sh->sh_sopool); while (so) { struct slab_object *so_tmp = so; so = LDAP_LIST_NEXT(so, so_link); ch_free(so_tmp); } } if (key != NULL) { ber_memfree_x(sh->sh_base, NULL); ber_memfree_x(sh, NULL); } }