1)參考:http://www.linuxidc.com/Linux/2012-06/63754.htmlinux
2)測試代碼:測試
#include <stdlib.h> #include <malloc.h> #include <string.h> void test() { int *ptr = (int *)malloc(sizeof(int)*10); ptr[10] = 7; // 內存越界 memcpy(ptr +1, ptr, 5); // 踩內存 free(ptr); free(ptr);// 重複釋放 int *p1; *p1 = 1; // 非法指針 } int main(void) { test(); return 0; }
3)檢查結果指針