In my sample program I get “corruption of heap” error at the following line.
ofstream filePossibleHaplotype;
“Windows has triggered a breakpoint in Project_Name.exe.
This may be due to a corruption of the heap, which indicates a bug in Project_Name.exe or any of the DLLs it has loaded.”
How does declaration of a file stream object cause this error ?
[EDIT – Added few snippets of code]
SET = 1
NOT_SET = 0
LENGTH = 5
void fill_Unique_Bit_Array()
{
int zeroFlag = NOT_SET;
int oneFlag = NOT_SET;
bit_array = new int(LENGTH);
for(int i =0; i<LENGTH; i++)
{
for(int j =0; j<NUMBER_OF_READS; j++)
{
if(readMartixArray[j][i] == '0')
zeroFlag = SET;
else if (readMartixArray[j][i] == '1')
oneFlag = SET;
}
if(zeroFlag==SET && oneFlag==SET)
bit_array[i] = SET + SET;
else if(zeroFlag==SET && oneFlag==NOT_SET)
bit_array[i] = NOT_SET;
else if(zeroFlag==NOT_SET && oneFlag==SET)
bit_array[i] = SET;
zeroFlag = NOT_SET;
oneFlag = NOT_SET;
}
reverse_bit_array = array_Reverse(bit_array, LENGTH);
}
This function calls,
void find_all_possible_combinations(int ,int, int, int )
{
ofstream filePossibleHaplotype;
}
which leads to crash of heap memory.
The issue was with dynamic memory allocation of bit_array. I created a normal static array and the code worked fine. But I am not sure of why the dynamic array allocation is causing an issue.I have declared the int pointer as a global variable.
bit_array = new int(LENGTH);