env_checked = TRUE;
}
- new = g_slice_alloc (sizeof (rspamd_mempool_t));
- memset (new->pools, 0, sizeof (gpointer) * RSPAMD_MEMPOOL_MAX);
+ new = g_slice_alloc0 (sizeof (rspamd_mempool_t));
new->destructors = g_array_sized_new (FALSE, FALSE,
sizeof (struct _pool_destructors), 32);
rspamd_mempool_create_pool_type (new, RSPAMD_MEMPOOL_NORMAL);
/* Set it upon first call of set variable */
- new->variables = NULL;
new->elt_len = size;
if (tag) {
ptr = g_malloc (size);
POOL_MTX_UNLOCK ();
- rspamd_mempool_add_destructor (pool, g_free, ptr);
+
+ if (pool->trash_stack == NULL) {
+ pool->trash_stack = g_ptr_array_sized_new (128);
+ }
+
+ g_ptr_array_add (pool->trash_stack, ptr);
return ptr;
}
{
struct _pool_chain *cur;
struct _pool_destructors *destructor;
+ gpointer ptr;
guint i, j;
POOL_MTX_LOCK ();
g_hash_table_destroy (pool->variables);
}
+ if (pool->trash_stack) {
+ for (i = 0; i < pool->trash_stack->len; i++) {
+ ptr = g_ptr_array_index (pool->trash_stack, i);
+ g_free (ptr);
+ }
+
+ g_ptr_array_free (pool->trash_stack, TRUE);
+ }
+
g_atomic_int_inc (&mem_pool_stat->pools_freed);
POOL_MTX_UNLOCK ();
g_slice_free (rspamd_mempool_t, pool);
pthread_mutex_init (res, &mattr);
rspamd_mempool_add_destructor (pool,
(rspamd_mempool_destruct_t)pthread_mutex_destroy, res);
+ pthread_mutexattr_destroy (&mattr);
return res;
}
pthread_rwlock_init (res, &mattr);
rspamd_mempool_add_destructor (pool,
(rspamd_mempool_destruct_t)pthread_rwlock_destroy, res);
+ pthread_rwlockattr_destroy (&mattr);
return res;
}