Exemplo n.º 1
0
/* Function    : CyU3PMemFree
 * Description : This function frees memory previously allocated using CyU3PMemAlloc.
 * Parameters  :
 *               size : Pointer to memory block to be freed.
 */
void
CyU3PMemFree (
        void *mem_p)
{
#ifdef CYFXTX_ERRORDETECTION
    MemBlockInfo *block_p;
    uint32_t     *endsig_p;
#endif

    /* Validity check for the pointer. */
    if ((uint32_t)mem_p < CY_U3P_MEM_HEAP_BASE)
        return;

#ifdef CYFXTX_ERRORDETECTION
    /* If memory checks are enabled, ensure that the block is valid; and perform
       the required book-keeping as well. */
    if (glMemEnableChecks)
    {
        block_p  = (MemBlockInfo *)((uint8_t *)mem_p - sizeof (MemBlockInfo));
        endsig_p = (uint32_t *)((uint8_t *)block_p + block_p->alloc_size - sizeof (uint32_t));

        if ((block_p->start_sig != CY_U3P_MEM_START_SIG) || (*endsig_p != CY_U3P_MEM_END_SIG))
        {
            /* Notify the user that memory has been corrupted. */
            if (glMemBadCb != 0)
                glMemBadCb (mem_p);
        }

        glMemFreeCnt++;

        /* Update the in-use linked list to drop the freed-up block. */
        if (block_p->next_blk != 0)
            block_p->next_blk->prev_blk = block_p->prev_blk;
        if (block_p->prev_blk != 0)
            block_p->prev_blk->next_blk = block_p->next_blk;
        if (glMemInUseList == block_p)
        {
            glMemInUseList = block_p->prev_blk;
        }

        mem_p = (void *)block_p;
    }
#endif

    CyU3PByteFree (mem_p);
}
void
CyU3PMemFree (
        void *mem_p)
{
    CyU3PByteFree (mem_p);
}