-
October 28th, 2013, 04:12 PM
#1
MFC CRecordset heap corruption detected at Close()
I recently upgraded my operating system from Windows XP to Windows 7 SP1 64 bit. We are using Visual Studio 2008 Professional Edition and Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production.
When I try to execute this code I am getting the below exceptions
HTML Code:
try {
CDatabase *pDatabase = CDatabaseConnection::getDatabaseConnectionProcessLog();
ORSProcessLog rsProcessLog(pDatabase);
CString strFilter = _T("SELECT PROCESS_ID, MESSAGE FROM OP_PROCESS_LOG");
rsProcessLog.SetRowsetSize(1);
if( !rsProcessLog.Open(CRecordset::dynaset, strFilter, CRecordset::appendOnly) )
return;
if( !rsProcessLog.CanAppend() )
return;
rsProcessLog.AddNew();
rsProcessLog.m_PROCESS_ID = gcsProcessID;
rsProcessLog.m_MESSAGE = csMessageA;
rsProcessLog.Update();
rsProcessLog.Close();
}
catch ( CDBException* pEx )
{
bException = true;
pEx->GetErrorMessage(szCause, 255);
}
catch( CException* pEx )
{
bException = true;
pEx->GetErrorMessage(szCause, 255);
}
where rsProcessLog is the CRecordset object using a successfully connected database pointer pDatabase
In 32- bit Debug version I get a message box at rsProcessLog.Close(); with the below text Debug Error
Program: ......\Test.exe
HEAP CORRUPTION DETECTED: after Normal block (#506) at 0x0087F628. CRT detected that the application wrote to memory after end of heap buffer.
Memory allocated at f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dbcore.cpp(2626)
(Please Retry to debug the application)
In 32- bit Release version I get a message box at rsProcessLog.Close(); with the below text Windows has triggered a breakpoint in Test.exe
This may be due to a corruption of the heap, which indicates a bug in Test.exe or any of the DLLS it has loaded.
This may also be due to the user pressing F12 while Test.exe has focus.
The output window may have more diagnostic information.
The above code was a working code in Windows XP with the rest of the env remaining the same and it continues to run in Windows XP but not in Windows 7. Any help will be greatly appreciated.
-
October 29th, 2013, 03:46 AM
#2
Re: MFC CRecordset heap corruption detected at Close()
Victor Nijegorodov
-
October 29th, 2013, 01:24 PM
#3
Re: MFC CRecordset heap corruption detected at Close()
Thanks. Victor.
Unfortunately the question was "Not Answered" in the oracle forums thread.
-
October 29th, 2013, 01:38 PM
#4
Re: MFC CRecordset heap corruption detected at Close()
However, there is a lot of discussions about the problems with Oracle client 11 drivers when using CRecordset class.
Could you try with v.10? Or with SQL Server database? Would it work or not?
discussions
Victor Nijegorodov
-
October 29th, 2013, 03:18 PM
#5
Re: MFC CRecordset heap corruption detected at Close()
Originally Posted by anandvijayakumar
When I try to execute this code I am getting the below exceptions
You didn't tell us which line throws the exception.
If the exception occurs after you leave that block (the curly brace that matches the try opening brace), then please answer the next question.
Code:
ORSProcessLog rsProcessLog(pDatabase);
What is this ORSProcessLog class? Since it is a local object (at least that what it looks like), the destructor gets called. What does the destructor do, and is it coded correctly (a destructor cannot throw exceptions or call functions that throw exceptions, unless the destructor catches everything).
The above code was a working code in Windows XP with the rest of the env remaining the same and it continues to run in Windows XP but not in Windows 7.
This means really nothing. There are thousands of buggy apps that seem to work in XP, but then Windows 7 reveals the bug(s).
Regards,
Paul McKenzie
-
October 29th, 2013, 03:25 PM
#6
Re: MFC CRecordset heap corruption detected at Close()
Thanks. Paul for your response.
If you see my above post. I have mentioned the error happens at rsProcessLog.Close(); It happens in both Debug and Release version with different error messages.
ORSProcessLog class is derived from CRecordset and the ~ORSProcessLog does nothing it just has empty brackets {}.
-
October 29th, 2013, 03:32 PM
#7
Re: MFC CRecordset heap corruption detected at Close()
Originally Posted by anandvijayakumar
Thanks. Paul for your response.
If you see my above post. I have mentioned the error happens at rsProcessLog.Close(); It happens in both Debug and Release version with different error messages.
Can you debug into the Close() function? If so, what is the code that throws the exception?
The first thing you should be doing is identify the exact line of code that throws the exception, and then determine what makes that line throw.
Regards,
Paul McKenzie
-
October 29th, 2013, 03:52 PM
#8
Re: MFC CRecordset heap corruption detected at Close()
Close() calls the CRecordset.Close() function.
In void CRecordset::Close() function it calls CRecordset::FreeRowset();
It tries to delete the rowset status
delete [] m_rgRowStatus;
the exception is thrown right there in this line delete [] m_rgRowStatus;
-
October 29th, 2013, 03:56 PM
#9
Re: MFC CRecordset heap corruption detected at Close()
to be more precise the overloaded delete() it fails in this function.
if (!CheckBytes(pbData(pHead) + pHead->nDataSize, _bNoMansLandFill, nNoMansLandSize))
and then throws this exception
if (pHead->szFileName)
{
_RPT5(_CRT_ERROR, "HEAP CORRUPTION DETECTED: after %hs block (#%d) at 0x%p.\n"
"CRT detected that the application wrote to memory after end of heap buffer.\n"
_ALLOCATION_FILE_LINENUM,
szBlockUseName[_BLOCK_TYPE(pHead->nBlockUse)],
pHead->lRequest,
(BYTE *) pbData(pHead),
pHead->szFileName,
pHead->nLine);
}
-
October 29th, 2013, 04:25 PM
#10
Re: MFC CRecordset heap corruption detected at Close()
Originally Posted by anandvijayakumar
Close() calls the CRecordset.Close() function.
In void CRecordset::Close() function it calls CRecordset::FreeRowset();
It tries to delete the rowset status
delete [] m_rgRowStatus;
What is the value of m_rgRowStatus? Does it look like a valid pointer value? If it does look valid, what does it point to? Does it point to "valid looking" data, or garbage?
Also, cut down the try block to doing very few things, then add lines until the program breaks. For example:
Code:
CDatabase *pDatabase = CDatabaseConnection::getDatabaseConnectionProcessLog();
ORSProcessLog rsProcessLog(pDatabase);
CString strFilter = _T("SELECT PROCESS_ID, MESSAGE FROM OP_PROCESS_LOG");
rsProcessLog.SetRowsetSize(1);
if( !rsProcessLog.Open(CRecordset::dynaset, strFilter, CRecordset::appendOnly) )
return;
rsProcessLog.Close();
Does this throw an exception? If not, then keep adding a line at a time and run. Once it breaks, then you know which one of those functions alters or affects m_rgRowStatus.
Regards,
Paul McKenzie
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|