FIX: Memory Leak when Requerying with a CTime Parameter

Last reviewed: September 18, 1997
Article ID: Q115035
1.50 WINDOWS kbprg kbfixlist kbbuglist

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), included with:

        - Microsoft Visual C++ for Windows, version 1.5
    

SYMPTOMS

When running an MFC application that uses the database classes, the following message may appear in the Output Window of the debugger:

   Detected memory leaks!
   Dumping objects ->
   {45}dbrfx.cpp(1331) : non-object block at $3FF74442, 16 bytes long
   Object dump complete.

The message only occurs when you select a date/time field of a table, use RFX_Date() to map a CTime variable to the field, and call Requery().

CAUSE

Line 1331 in DBRFX.CPP includes the following code:

    // Allocate TIMESTAMP_STRUCT for SQLBindCol
    pFX->m_prs->m_pvFieldProxy[nField-1] = new TIMESTAMP_STRUCT;

This line runs each time date/time fields are bound to CTime recordset variables using the RFX_Date() record field exchange function. When doing a Requery(), the fields of the result set must be rebound to the CRecordset's variables, and thus a Requery() causes the memory leak to occur. The line of code shown above assigns a new value to an element of a pointer array, leaving the previous allocation stranded in memory.

RESOLUTION

To resolve the memory leak, override the virtual Requery() function of CRecordset and delete the elements of the m_pvFieldProxy array. The following code demonstrates what to do:

BOOL CMyAppRecordSet::Requery() {

    // delete proxies for recordset fields
    if (m_pvFieldProxy != NULL)
    {
        for (UINT nField = 0; nField != m_nFields; nField++)
            delete m_pvFieldProxy[nField];
    }

    return CRecordset::Requery();
}

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ version 1.51.


Additional reference words: ODBC 1.50 2.50
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: MfcDatabase
Keywords : kb16bitonly MfcDatabase kbbuglist kbfixlist kbprg
Technology : kbMfc
Version : 1.50
Platform : WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.