12???????C??????????
???????????? ???????[ 2012/9/7 9:56:58 ] ????????????
????5??free()????
?????????????????????????'freeze'????????????'zebra'?????????
#include<stdio.h>
int main(int argc?? char *argv[])
{
char *ptr = (char*)malloc(10);
if(NULL == ptr)
{
printf("
Malloc failed
");
return -1;
}
else if(argc == 1)
{
printf("
Usage
");
}
else
{
memset(ptr?? 0?? 10);
strncpy(ptr?? argv[1]?? 9);
while(*ptr != 'z')
{
if(*ptr == '')
break;
else
ptr++;
}
if(*ptr == 'z')
{
printf("
String contains 'z'
");
// Do some more processing
}
free(ptr);
}
return 0;
}
????????????????????????????????“ptr”?????while?????“ptr”?洢????????????“zebra”???while????????????????????????free()??????????malloc()??????????“freeze”???“ptr”?洢????????while??????????????′???free()????????????????seg-fault?????????
????6?????_exit???
??????????????????У?atexit()????б???????????
#include<stdio.h>
void func(void)
{
printf("
Cleanup function called
");
return;
}
int main(void)
{
int i = 0;
atexit(func);
for(;i<0xffffff;i++);
_exit(0);
}
???????????_exit()???????????ú???????е???atexit()????????????????atexit()??????exit()????“return”?????????
??????
???·???
??????????????????
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