void context_free(context_t *context) { if (context) { pki_passport_destroy(context->passport); linkst_free(context->linkst); ftable_delete(context->ftable); ctable_delete(context->ctable); ctable_delete(context->atable); bitpool_free(context->bitpool); session_free(context->access_session); free(context); } }
// Release a block from the heapAllocator void heap_deallocate( heapAllocator* heap, void* data ) { if ( data == NULL ) return; vmutex_lock( &allocator_mutex ); // Check if it's in a bitpool bitpool* bit_pool = heap_findBitpoolForData( heap, data ); if ( bit_pool ) { bitpool_free( bit_pool, data ); vmutex_unlock( &allocator_mutex ); return; } block* b = (block*)((uint8_t*)data - sizeof( block )); vAssert( !b->free ); assertBlockInvariants( b ); #ifdef MEM_DEBUG_VERBOSE printf("Allocator freed address: " xPTRf ".\n", (uintptr_t)b->data ); #endif b->free = true; addToFreeList( heap, b ); heap->total_free += b->size; heap->total_allocated -= b->size; checkFree( heap, b ); // Try to merge blocks if ( b->next && b->next->free ) { checkFree( heap, b->next ); blockMerge( heap, b, b->next ); } if ( b->prev && b->prev->free ) { checkFree( heap, b->prev ); blockMerge( heap, b->prev, b ); } --heap->allocations; vmutex_unlock( &allocator_mutex ); }