Dear folks,
my C++ program hangs during memory deallocation.
Does anybody knows how one can find such a terrible BUG and what can
be the reason?
I know what is "memory leak", "segmentation fault", "step-on-others-toe",
but I think one of the bugs above can not hang the program.
Am I right?
How I allocate memory:
Code://allocate CSYMBOL vector in memory CSYMBOL *CSYMBOL_vector(long symbLen, long symbNumb) { long i=0; CSYMBOL *res; #ifdef CPP_FLAG res=new CSYMBOL [symbNumb]; #else res=(CSYMBOL *) malloc(symbNumb*sizeof(CSYMBOL)); if(!res) { printf("Not enough memory to allocate COMPLEX symbol\n"); exit(1); //terminate program if out of memory } #endif for(i=0;i<symbNumb;i++) { #ifdef CPP_FLAG res[i].x=new CPOINT [symbLen]; #else res[i].x=CPOINT_vector(symbLen); if(!res[i].x) { printf("Not enough memory to allocate COMPLEX symbol (1)\n"); exit(1); //terminate program if out of memory } #endif res[i].symbLen=symbLen; }//end of for return res; }
And this is deallocation part:
P.S. If somebody need:Code://deallocate memory long free_CSYMBOL_vector(CSYMBOL *symb2free, long symbNumb) { long i=0; for(i=0;i<symbNumb;i++) if(symb2free[i].x!=NULL) { #ifdef CPP_FLAG delete [] symb2free[i].x; //the program hangs here if CPP_FLAG is defined #else free(symb2free[i].x); //or here (no CPP_FLAG) #endif } #ifdef CPP_FLAG ; //do nothing #else else { printf("Attempt to deallocate memory which was not allocated\n"); exit(1); } #endif #ifdef CPP_FLAG delete [] symb2free; #else free(symb2free); #endif return 0; }
gcc --version
2.95.2
---
uname -a
Linux name 2.4.20 #2 SMP Fri Feb 20 17:07:59 CET 2004 i686 unknown



LinkBack URL
About LinkBacks


