MFC CRecordset heap corruption detected at Close()
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: MFC CRecordset heap corruption detected at Close()

  1. #1
    Join Date
    Aug 2013
    Posts
    6

    Post 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.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,011

    Re: MFC CRecordset heap corruption detected at Close()

    See if this discussion could help:
    https://forums.oracle.com/thread/2297218
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2013
    Posts
    6

    Re: MFC CRecordset heap corruption detected at Close()

    Thanks. Victor.
    Unfortunately the question was "Not Answered" in the oracle forums thread.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,011

    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

  5. #5
    Join Date
    Apr 1999
    Posts
    27,418

    Re: MFC CRecordset heap corruption detected at Close()

    Quote Originally Posted by anandvijayakumar View Post
    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

  6. #6
    Join Date
    Aug 2013
    Posts
    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 {}.

  7. #7
    Join Date
    Apr 1999
    Posts
    27,418

    Re: MFC CRecordset heap corruption detected at Close()

    Quote Originally Posted by anandvijayakumar View Post
    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

  8. #8
    Join Date
    Aug 2013
    Posts
    6

    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;

  9. #9
    Join Date
    Aug 2013
    Posts
    6

    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);
    }

  10. #10
    Join Date
    Apr 1999
    Posts
    27,418

    Re: MFC CRecordset heap corruption detected at Close()

    Quote Originally Posted by anandvijayakumar View Post
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center