|
发表于 2007-8-30 10:48:01
|
显示全部楼层
内存释放出错?
/*************************************************************************
* FUNCTION
*
* kal_adm_free
*
* DESCRIPTION
*
* Free a memory block.
*
* PARAMETERS
*
* adm_id - ID of memory pool
* mem_addr - memory address to be freed
*
* RETURNS
*
* None
*
*************************************************************************/
void kal_adm_free(KAL_ADM_ID adm_id, void *mem_addr)
{
ADM_MB_HEAD *adm_mb_head, *merge_adm_mb_head;
ADM_MB_LOG *adm_mb_log;
ADM_MB_FOOT *adm_mb_foot;
#ifdef DEBUG_ADM
kal_uint32 owner;
#endif
if (adm_id == NULL)
EXT_ASSERT(0, 0, 0, 0);
ASSERT(((ADM_CB *)adm_id)->adm_id == ADM_ID);
if (mem_addr == NULL)
return;
#ifdef DEBUG_ADM
kal_get_my_task_index(&owner);
ASSERT(owner == ((ADM_CB *)adm_id)->owner);
#endif
if (((ADM_CB *)adm_id)->islogging == 1) {
/* adjust the address if logging is enabled */
mem_addr = (void *)((kal_uint8 *)mem_addr - sizeof(ADM_MB_LOG));
}
adm_mb_head = ADM_GET_MB_HEAD(mem_addr);
ASSERT(ADM_MB_STATE(adm_mb_head) == ADM_INUSE);
#if 0
/* under construction !*/
#endif
if (((ADM_CB *)adm_id)->islogging == 1) {
/* check guard pattern in the log and the footer */
adm_mb_log = ADM_GET_MB_LOG(adm_mb_head);
ASSERT(adm_mb_log->stamp == ADM_MB_LOG_STAMP);
adm_mb_foot = ADM_GET_MB_FOOT(adm_mb_head);
ASSERT(adm_mb_foot->stamp == ADM_MB_FOOT_STAMP);
}
/* merge with free neighbors */
if (ADM_MB_PREV(adm_mb_head) != NULL && ADM_MB_STATE(ADM_MB_PREV(adm_mb_head)) == ADM_FREE) {
merge_adm_mb_head = ADM_MB_PREV(adm_mb_head);
/* remove the neighbor from block lists */
kal_adm_removefrombl(merge_adm_mb_head);
merge_adm_mb_head->next = adm_mb_head->next;
/* update (adm_mb_head->next) memory block */
if (adm_mb_head->next != NULL)
adm_mb_head->next->prev = ADM_MB_SET_PREV(adm_mb_head->next->prev, merge_adm_mb_head);
adm_mb_head = merge_adm_mb_head;
}
if (adm_mb_head->next != NULL && ADM_MB_STATE(adm_mb_head->next) == ADM_FREE) {
merge_adm_mb_head = adm_mb_head->next;
/* remove the neighbor from block lists */
kal_adm_removefrombl(merge_adm_mb_head);
adm_mb_head->next = merge_adm_mb_head->next;
/* update (adm_mb_head->next) memory block */
if (merge_adm_mb_head->next != NULL)
merge_adm_mb_head->next->prev = ADM_MB_SET_PREV(merge_adm_mb_head->next->prev, adm_mb_head);
}
/* set the memory block as FREE */
ADM_MB_SET_FREE(adm_mb_head);
kal_adm_add2bl((ADM_CB *)adm_id, adm_mb_head);
} |
|