65,211
社区成员
发帖
与我相关
我的任务
分享
void GetMemory2(char **p, int num)
{
*p = (char *)malloc(num);
}
void Test(void)
{
char *str = NULL;
GetMemory(&str, 100);
strcpy(str, "hello");
printf(str);
free(str );
}
//是否存在内存泄露???????????
下列特殊情况,程式崩溃!但不会内存泄露
void GetMemory2(char **p, int num)
{
*p = (char *)malloc(num); //内存申请失败,此时*p=NULL;
}
void Test(void)
{
char *str = NULL;
GetMemory(&str, 100);
strcpy(str, "hello"); //对0地址进行读写操作,直接就over了
printf(str);
free(str );
}