日期:2014-05-16 浏览次数:20776 次
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
typedef struct{
char a[20];
char b[100];
char c[150];
}test;
int main()
{
test *p2 = (test *)malloc(sizeof(test)*100);
if(p2 = NULL)
{
printf("malloc p2 error");
exit(1);
}
int a;
while(1)
{
test *p2 = (test *)malloc(sizeof(test)*100);
if(p2 = NULL)
{
printf("malloc p2 error");
exit(1);
}
sleep(0.5);
if(p2 != NULL)
{
free(p2);
p2 = NULL;
}
}
return 0;
}