oal_uint32 dmac_data_acq_mem_free(oal_void) { if (OAL_PTR_NULL != g_st_data_acq.st_daq_prep_info.puc_start_addr) { oal_free((void *)g_st_data_acq.st_daq_prep_info.puc_start_addr); g_st_data_acq.st_daq_prep_info.puc_start_addr = OAL_PTR_NULL; } return OAL_SUCC; }
/** Free previously allocated memory * @param buf Previously allocated buffer. */ void cmsMem_free(void *buf) { UINT32 size; if (buf != NULL) { UINT32 *intBuf = (UINT32 *) (((UINT32) buf) - CMS_MEM_HEADER_LENGTH); #ifdef CMS_MEM_LEAK_TRACING { AllocRecord *allocRec; dlist_for_each_entry(allocRec, &glbAllocRec, dlist) if (allocRec->bufAddr == buf) break; if ((DlistNode *) allocRec != &glbAllocRec) { dlist_unlink((struct dlist_node *) allocRec); free(allocRec); } else { /* * Buffers allocated from shared mem could have been freed by * another app, so if we have an alloc record but cannot find * it in shared mem, ignore it. But if the alloc record is in * private heap, that is an error. */ if (!IS_IN_SHARED_MEM(buf)) { cmsLog_error("possible double free, could not find allocRec for buf %p", buf); } } } #endif size = intBuf[1]; if (intBuf[1] != (intBuf[2] ^ 0xffffffff)) { cmsLog_error("memory underflow detected, %d %d", intBuf[1], intBuf[2]); cmsAst_assert(0); return; } #ifdef CMS_MEM_DEBUG { UINT32 allocSize, intSize, roundup4Size, i; UINT8 *charBuf = (UINT8 *) buf; allocSize = REAL_ALLOC_SIZE(intBuf[1]); intSize = allocSize / sizeof(UINT32); roundup4Size = ROUNDUP4(intBuf[1]); for (i=intBuf[1]; i < roundup4Size; i++) { if (charBuf[i] != (UINT8) (CMS_MEM_FOOTER_PATTERN & 0xff)) { cmsLog_error("memory overflow detected at idx=%d 0x%x 0x%x 0x%x", i, charBuf[i], intBuf[intSize-1], intBuf[intSize-2]); cmsAst_assert(0); return; } } if ((intBuf[intSize - 1] != CMS_MEM_FOOTER_PATTERN) || (intBuf[intSize - 2] != CMS_MEM_FOOTER_PATTERN)) { cmsLog_error("memory overflow detected, 0x%x 0x%x", intBuf[intSize - 1], intBuf[intSize - 2]); cmsAst_assert(0); return; } #ifdef CMS_MEM_POISON_ALLOC_FREE /* * write garbage into buffer which is about to be freed to detect * users of freed buffers. */ memset(intBuf, CMS_MEM_FREE_PATTERN, allocSize); #endif } #endif /* CMS_MEM_DEBUG */ buf = intBuf; /* buf points to real start of buffer */ #ifdef MDM_SHARED_MEM if (IS_IN_SHARED_MEM(buf)) { brel(buf); } else #endif { oal_free(buf); mStats.bytesAllocd -= size; mStats.numFrees++; } }
/***************************************************************************** 函 数 名 : oam_cfg_get_all_item 功能描述 : OAM模块加载的时候将配置文件中的所有配置信息保存到一个内部结构中 输入参数 : 无 输出参数 : 无 返 回 值 : 调用函数 : 被调函数 : 修改历史 : 1.日 期 : 2014年4月9日 作 者 : z00237171 修改内容 : 新生成函数 *****************************************************************************/ oal_int32 oam_cfg_get_all_item(oal_void) { oal_int32 al_default_cfg_data[OAM_CFG_TYPE_BUTT] = {0}; oal_uint8 *puc_plaintext; oal_uint8 *puc_ciphertext; oal_uint32 ul_file_size = 0; oal_uint32 ul_loop; oal_int32 l_ret; oal_int i_key[OAL_AES_KEYSIZE_256] = {0x1,0x2,0x3,0x4d,0x56,0x10,0x11,0x12, 0x1,0x2,0x3,0x4d,0x56,0x10,0x11,0x12, 0x1,0x2,0x3,0x4d,0x56,0x10,0x11,0x12, 0x1,0x2,0x3,0x4d,0x56,0x10,0x11,0x12}; oal_aes_key_stru st_aes_key; /* 保存默认配置,如果获取配置文件中信息的时候中间有失败的情况,则需要恢复 前面全局配置信息,其它模块加载的时候可以按照默认配置加载 */ for (ul_loop = 0; ul_loop < OAM_CFG_TYPE_BUTT; ul_loop++) { al_default_cfg_data[ul_loop] = g_ast_cfg_data[ul_loop].l_val; } /* 获取文件大小并获取文件指针 */ l_ret = oal_file_size(&ul_file_size); if (OAL_SUCC != l_ret) { OAL_IO_PRINT("oam_cfg_get_all_item::get file size failed!\n"); return l_ret; } /* 将配置文件中的所有数据读到一个缓冲区里,此时数据是加密的 */ puc_ciphertext = oal_memalloc(ul_file_size + OAM_CFG_STR_END_SIGN_LEN); if (OAL_PTR_NULL == puc_ciphertext) { OAL_IO_PRINT("oam_cfg_get_all_item::alloc ciphertext buf failed! load ko with default cfg!\n"); return OAL_ERR_CODE_PTR_NULL; } OAL_MEMZERO(puc_ciphertext, ul_file_size + OAM_CFG_STR_END_SIGN_LEN); l_ret = oam_cfg_read_file_to_buf((oal_int8 *)puc_ciphertext, ul_file_size); if (OAL_SUCC != l_ret) { OAL_IO_PRINT("oam_cfg_get_all_item::get cfg data from file failed! fail id-->%d\n", l_ret); oal_free(puc_ciphertext); return l_ret; } /* 申请明文空间,并将密文解密 */ puc_plaintext = oal_memalloc(ul_file_size + OAM_CFG_STR_END_SIGN_LEN); if (OAL_PTR_NULL == puc_plaintext) { OAL_IO_PRINT("oam_cfg_get_all_item::alloc pc_plaintext buf failed! load ko with default cfg!\n"); oal_free(puc_ciphertext); return OAL_ERR_CODE_PTR_NULL; } OAL_MEMZERO(puc_plaintext, ul_file_size + OAM_CFG_STR_END_SIGN_LEN); /* 解密 */ l_ret = (oal_int32)oal_aes_expand_key(&st_aes_key,(oal_uint8 *)i_key,OAL_AES_KEYSIZE_256); if (OAL_SUCC != l_ret) { oal_free(puc_plaintext); oal_free(puc_ciphertext); return l_ret; } oam_cfg_decrypt_all_item(&st_aes_key, (oal_int8 *)puc_ciphertext, (oal_int8 *)puc_plaintext, ul_file_size); /* 获取配置文件中每一项的信息,保存到OAM内部结构中 */ for (ul_loop = 0; ul_loop < OAM_CFG_TYPE_BUTT; ul_loop++) { l_ret = oam_cfg_get_one_item((oal_int8 *)puc_plaintext, g_ast_cfg_data[ul_loop].pc_section, g_ast_cfg_data[ul_loop].pc_key, &g_ast_cfg_data[ul_loop].l_val); /* 如果获取某一配置值不成功,则恢复配置项的默认值 */ if (OAL_SUCC != l_ret) { OAL_IO_PRINT("oam_cfg_get_all_item::get cfg item fail! ul_loop=%d\n", ul_loop); oam_cfg_restore_all_item(al_default_cfg_data); oal_free(puc_plaintext); oal_free(puc_ciphertext); return l_ret; } } /* 释放缓冲区 */ oal_free(puc_plaintext); oal_free(puc_ciphertext); return OAL_SUCC; }