Heap error

In below code, FileType is a Base class with function VerifyData() as defined. Derived classes then inherit this function and in the main program, instantiate a pointer and call VerifyData(). It gives this error:

HEAP[sample.exe]: Invalid address specified to RtlFreeHeap( 0000000864F60000, 0000000865131A30 )
(246f8.23f18): Break instruction exception - code 80000003 (first chance)

If I disable this function call, the entire program runs just fine.

After having spent so much time to isolate the problem, I am not able to understand what the exact problem is, in this code. Any help is appreciated.

Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
void FileType::VerifyData() const
{
	if(FileList.size() <= 0)
	{
		return;
	}

	for(DWORD i = 0; i < FileList.size(); ++i)
	{
		ifstream baseFileStream(BaseFileName.c_str());
		ifstream targetFileStream(FileList[i].c_str());
		
		string line1, line2;
		BOOL mismatchFound = false;
		DWORD lineNum = 0;

		wcout << L"Verifying files: " << FileList[i].c_str() << L" and " << BaseFileName.c_str();
		
		while(!targetFileStream.eof() || !baseFileStream.eof())
		{
			++lineNum;
			
			getline(targetFileStream, line1);
			getline(baseFileStream, line2);

			if(line1.compare(line2) != 0)
			{
				
				//wcout << L"- Mismatch found in target file at line " << lineNum << endl;
								
				//cout << line1.c_str() << endl;
				//cout << line2.c_str() << endl;
				
				mismatchFound = true;
				break;
			}
		}		
		if(mismatchFound == false)
		{
			wcout << L"- Files consistent " << endl;
		}
		
		baseFileStream.close();
		targetFileStream.close();
	}
}
In Visual Studio (which is what I know), you can break and it shows you the call stack and you can simply refer to the call stack to determine where in the code the problem appears, exactly. Can you do that with your compiler/IDE?

Quickly glancing at your code, I see you use wcout, but you have strings (line1, line2). So you seem to be mixing string data types. You should commit to one string type and then be consistent. If you ask me, commit to using wide strings everywhere. May or may not be a problem here. Just saying it is best to be consistent.
Well, I had already looked into the stacks, with no avail. The bug is somewhere in the usages of filestreams. Because disabling the filestream code fixes the code.

Anyway, I have modified the code to rely on "FC" command for file comparison and use their exit codes. Works better that way.

Thanks!
Topic archived. No new replies allowed.