??????????????
???????????? ???????[ 2011/12/20 14:10:21 ] ????????
????????????????????????о?????????????????????????????????o?????????????????memset??memmove??strcpy??strncpy??strcat??sprintf???????????????????????????????????????????????????????????????
#define MAX_SET_STR_LENGTH 50
#define MAX_GET_STR_LENGTH 100
int* process(char* pMem?? int size)
{
char localMemory[MAX_SET_STR_LENGTH] = {0};
int* pData = NULL;
/* code process */
memset(localMemory?? 1?? MAX_GET_STR_LENGTH);
memmove(pMem?? localMemory?? MAX_GET_STR_LENGTH);
return pData;
}
??????δ?????????????????????????localMemory???и???????????pMem???????????????????????????memset???С??????localMemory??????????????????????localMemory?????????????С???MAX_SET_STR_LENGTH?????????????????????ó???MAX_GET_STR_LENGTH?????????????????????????MAX_GET_STR_LENGTH??MAX_SET_STR_LENGTH???????????δ????????????????????????????????????????????????int*???ó????????
?????????????????????????????????????????????????????????????????????????д???????????????????Щ???????????????????????????????????????????????????????????????????Щ??????м????????????Ч??????memset??Щ?????滻????????????????????Щ???????????????????????????????ж?????
??????1??????????????malloc???????????????????????????????????????????????????size????伸????????????free?????????ж??????????β???????????????????????????????????δ???
void heap_memory_leak()
{
char* pMem = (char*)malloc(100);
pMem[-1] = 100;
pMem[100] = 100;
free(pMem);
}
????pMem[-1] = 100?????????? pMem[100]??????????
??????2??????????????????????д??????????????memset???????????????????????????
????a???????memset???????????????????
????#define memset(param?? value?? size) MEMORY_SET_PROCESS(__FUNCTION__?? __LINE__?? param?? value?? size)
????b????????????
typedef struct _MEMORY_NODE
{
char functionName[64];
int line;
void* pAddress;
int size;
struct _MEMORY_NODE* next;
}MEMORY_NODE;
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11