virtual void TearDown( void ) { if (m_mpool != NULL) { ib_mpool_destroy(m_mpool); } m_mpool = NULL; }
void ib_mpool_clear(ib_mpool_t *mp) { IB_FTRACE_INIT(ib_mpool_clear); ib_mpool_buffer_t *bufs = NULL; ib_mpool_buffer_t *next = NULL; if (mp == NULL) { IB_FTRACE_RET_VOID(); } /* @todo: destroy child pools */ int i = 0; ib_mpool_t *childs = NULL; ib_mpool_t *child_next = NULL; for (; childs; childs = child_next) { child_next = childs->next; ib_mpool_destroy(childs); } /* Move all out of the array of indexed, into busy_buffers */ for (; i < IB_MPOOL_MAX_INDEX; i++) { bufs = mp->indexed[i]; if (bufs != NULL) { for (; bufs != NULL; bufs = next) { next = bufs->next; bufs->prev = NULL; bufs->next = mp->busy_buffers; mp->busy_buffers = bufs; } mp->indexed[i] = NULL; } } /* Reset all buffers and index them */ size_t free_space = 0; bufs = mp->busy_buffers; for (; bufs != NULL; bufs = next) { next = bufs->next; /* Return some mem to the system if we have enough space already */ if (free_space > IB_MPOOL_INCREASE_FACTOR * IB_MPOOL_DEFAULT_PAGE_SIZE) { free(bufs); } else { IB_MPOOL_BUFFER_RESET(bufs); size_t slot = 0; /* Index the remaining buffer of the page */ IB_MPOOL_SET_INDEX(IB_MPOOL_BUFFER_AVAILABLE(bufs), slot); IB_MPOOL_ADD_BUFFER(mp, bufs, slot); free_space += bufs->size; } } mp->busy_buffers = NULL; mp->size = free_space; mp->inuse = 0; IB_FTRACE_RET_VOID(); }
void ib_cfgparser_destroy(ib_cfgparser_t *cp) { IB_FTRACE_INIT(ib_cfgparser_destroy); if (cp != NULL) { ib_mpool_destroy(cp->mp); } IB_FTRACE_RET_VOID(); }
/** * Destroy the eudoxus state when the transaction is complete. * * After the transaction is complete iterate over all of the states create * during the transaction and destroy them. * * @param[in] ib IronBee engine. * @param[in] tx Current transaction. * @param[in] event Event type (should always be @ref tx_finished_event) * @param[in] cbdata Callback data -- pointer to this module (@ref ib_module_t). * * @returns IB_OK on success. */ static ib_status_t ee_tx_finished_handler(ib_engine_t *ib, ib_tx_t *tx, ib_state_event_type_t event, void *cbdata) { ib_status_t rc; ib_hash_t *hash; ib_mpool_t *pool; const ib_module_t *m = (const ib_module_t *)cbdata; ia_eudoxus_state_t *state; ib_hash_iterator_t *iterator; rc = ib_tx_get_module_data(tx, m, &hash); if (rc != IB_OK || hash == NULL) { return rc; } rc = ib_mpool_create(&pool, "temp", NULL); if (rc != IB_OK) { return rc; } iterator = ib_hash_iterator_create(pool); if (iterator == NULL) { ib_mpool_destroy(pool); return IB_EALLOC; } for ( ib_hash_iterator_first(iterator, hash); ! ib_hash_iterator_at_end(iterator); ib_hash_iterator_next(iterator) ) { ib_hash_iterator_fetch(NULL, NULL, &state, iterator); if (state != NULL) { ia_eudoxus_destroy_state(state); state = NULL; } } ib_mpool_destroy(pool); return IB_OK; }
void ib_mpool_destroy(ib_mpool_t *mp) { IB_FTRACE_INIT(ib_mpool_destroy); ib_mpool_buffer_t *bufs = NULL; ib_mpool_buffer_t *next = NULL; if (mp == NULL) { IB_FTRACE_RET_VOID(); } /* @todo: destroy child pools */ int i = 0; ib_mpool_t *childs = NULL; ib_mpool_t *child_next = NULL; for (; childs; childs = child_next) { child_next = childs->next; ib_mpool_destroy(childs); } /* Move all out of the array of indexed, into busy_buffers */ for (; i < IB_MPOOL_MAX_INDEX; i++) { bufs = mp->indexed[i]; if (bufs != NULL) { for (; bufs != NULL; bufs = next) { next = bufs->next; bufs->prev = NULL; bufs->next = mp->busy_buffers; mp->busy_buffers = bufs; } mp->indexed[i] = NULL; } } /* Free all buffers */ bufs = mp->busy_buffers; for (; bufs != NULL; bufs = next) { next = bufs->next; free(bufs); } mp->busy_buffers = NULL; mp->size = 0; mp->inuse = 0; /* If there's a registered clean up function, use it */ if (mp->free != NULL) { mp->free(mp->free_data); } /* Check if mp is alloced inside another pool or not */ if (mp->parent == NULL) { free(mp); } IB_FTRACE_RET_VOID(); }
ib_status_t ib_cfgparser_create(ib_cfgparser_t **pcp, ib_engine_t *ib) { IB_FTRACE_INIT(ib_cfgparser_create); ib_mpool_t *pool; ib_status_t rc; /* Create parser memory pool */ rc = ib_mpool_create(&pool, ib->mp); if (rc != IB_OK) { rc = IB_EALLOC; goto failed; } /* Create the main structure in the memory pool */ *pcp = (ib_cfgparser_t *)ib_mpool_calloc(pool, 1, sizeof(**pcp)); if (*pcp == NULL) { rc = IB_EALLOC; goto failed; } (*pcp)->ib = ib; (*pcp)->mp = pool; /* Create the stack */ rc = ib_list_create(&((*pcp)->stack), pool); if (rc != IB_OK) { goto failed; } (*pcp)->cur_ctx = ib_context_main(ib); ib_list_push((*pcp)->stack, (*pcp)->cur_ctx); /* Create the block tracking list */ rc = ib_list_create(&((*pcp)->block), pool); if (rc != IB_OK) { goto failed; } /* Other fields are NULLed via calloc */ ib_log_debug(ib, 9, "Stack: ctx=%p site=%p(%s) loc=%p(%s)", (*pcp)->cur_ctx, (*pcp)->cur_site, (*pcp)->cur_site?(*pcp)->cur_site->name:"NONE", (*pcp)->cur_loc, (*pcp)->cur_loc?(*pcp)->cur_loc->path:"/"); IB_FTRACE_RET_STATUS(rc); failed: /* Make sure everything is cleaned up on failure */ if (pool != NULL) { ib_mpool_destroy(pool); } *pcp = NULL; IB_FTRACE_RET_STATUS(rc); }
/* * Destroy the memory pool of a radix (warning: this usually includes itself) * * @param radix the radix to destroy * * @returns Status code */ ib_status_t ib_radix_destroy(ib_radix_t **radix) { IB_FTRACE_INIT(ib_radix_destroy); if (!radix) { IB_FTRACE_RET_STATUS(IB_EINVAL); } ib_radix_node_destroy(*radix, &(*radix)->start, (*radix)->mp); ib_mpool_destroy((*radix)->mp); *radix = NULL; IB_FTRACE_RET_STATUS(IB_OK); }
/** * Release resources when the module is unloaded. * * All eudoxus engines created by the LoadEudoxus directive are destroyed. * * @param[in] ib Ironbee engine. * @param[in] m Module instance. * @param[in] cbdata Not used. */ static ib_status_t ee_module_finish(ib_engine_t *ib, ib_module_t *m, void *cbdata) { ib_status_t rc; ia_eudoxus_t *eudoxus; ib_mpool_t *pool; const ee_config_t *config = ee_get_config(ib); ib_hash_t *eudoxus_pattern_hash; ib_hash_iterator_t *iterator; if ( config == NULL || config->eudoxus_pattern_hash == NULL ) { return IB_OK; } eudoxus_pattern_hash = config->eudoxus_pattern_hash; rc = ib_mpool_create(&pool, "temp", NULL); if (rc != IB_OK) { return rc; } iterator = ib_hash_iterator_create(pool); if (iterator == NULL) { ib_mpool_destroy(pool); return IB_EALLOC; } for ( ib_hash_iterator_first(iterator, eudoxus_pattern_hash); ! ib_hash_iterator_at_end(iterator); ib_hash_iterator_next(iterator) ) { ib_hash_iterator_fetch(NULL, NULL, &eudoxus, iterator); if (eudoxus != NULL) { ia_eudoxus_destroy(eudoxus); } } ib_hash_clear(eudoxus_pattern_hash); ib_mpool_release(pool); return IB_OK; }
void MemoryPool::destroy() const { ib_mpool_destroy(ib()); }
virtual void TearDown() { ib_kvstore_destroy(&kvstore); ib_mpool_destroy(mp); ib_uuid_shutdown(); }