コード例 #1
0
ファイル: tag.c プロジェクト: WiseMan787/ralink_sdk
/**Frees allocated TagNode.
 *
 * @param hash - pointer to SFXHASH that should point to either ssn_tag_cache_ptr
 * or host_tag_cache_ptr.
 * @param node - pointer to node to be freed
 */
static void TagFree(
        SFXHASH *hash,
        TagNode *node
        )
{
    if (node == NULL)
        return;

    free((void *)node);
    tag_memory_usage -= memory_per_node(hash);
}
コード例 #2
0
ファイル: tag.c プロジェクト: WiseMan787/ralink_sdk
/** Allocate a TagNode
 *
 * Alocates a TagNode while guaranteeing that total memory usage remains within TAG_MEMCAP.
 * Least used nodes may be deleted from ssn_tag_cache and host_tag_cache to make space if
 * the limit is being exceeded.
 *
 * @param hash - pointer to SFXHASH that should point to either ssn_tag_cache_ptr
 * or host_tag_cache_ptr.
 *
 * @returns a pointer to new TagNode or NULL if memory couldn't * be allocated
 */
static TagNode * TagAlloc(
        SFXHASH *hash
        )
{
    TagNode *tag_node = NULL;

    if(tag_memory_usage + memory_per_node(hash) > TAG_MEMCAP)
    {
        /* aggressively prune */
        struct timeval tv;
        struct timezone tz;
        int pruned_nodes = 0;

        tag_alloc_faults++;

        gettimeofday(&tv, &tz);

        pruned_nodes = PruneTagCache((uint32_t)tv.tv_sec, 0);

        if(pruned_nodes == 0)
        {
            /* if we can't prune due to time, just try to nuke
             * 5 not so recently used nodes */
            pruned_nodes = PruneTagCache(0, 5);

            /* unlikely to happen since memcap has been reached */
            if (pruned_nodes == 0)
                return NULL;
        }
    }

    tag_node = (TagNode *)calloc(1, sizeof(TagNode));

    if (tag_node != NULL)
        tag_memory_usage += memory_per_node(hash);

    return tag_node;
}
コード例 #3
0
ファイル: tag.c プロジェクト: ulrich29/snort
/**Frees allocated TagNode.
 *
 * @param hash - pointer to SFXHASH that should point to either ssn_tag_cache_ptr
 * or host_tag_cache_ptr.
 * @param node - pointer to node to be freed
 */
static void TagFree(
        SFXHASH *hash,
        TagNode *node
        )
{
    if (node == NULL)
        return;

    if ( node->metric & TAG_METRIC_SESSION )
        s_exclusive = false;

    free((void *)node);
    tag_memory_usage -= memory_per_node(hash);
}