Every 1 second, function works. my system the linux. Runs suddenly dies.
-----global-------
static int arrayNum[33000];
-------------------
function(){
unsigned short int** US_INT;
try{
US_INT= new unsigned short int*[255];
for(int i = 0; i < 255; i++)
{
US_INT[i] = new unsigned short int[128];
memset(US_INT[i], 0, sizeof(unsigned short int) * 128);
}
double x;
double y;
int cnt= 0;
int nArrayCount=0;
for(int i = 0; i < 255; i++)
{
for(int j=0;j<128;j++){
x=j;
y=cnt
arrayNum[nArrayCount]=US_INT[i][j];
nArrayCount++;
}
cnt=cnt+(256/255);
}
for(int i = 0; i < 255; i++)
{
delete[] US_INT[i];
}
delete[] US_INT;
}
catch (const std::bad_alloc&) {
qDebug() << "alloc error";
for(int i = 0; i < 255; i++)
{
delete[] US_INT[i];
}
delete[] US_INT;
}
}
When memory allocation fails, the exception handling. However, the program will die. I made a mistake? output:
Error in `./TEST': double free or corruption (out): 0x34b00418