CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2000
    Location
    Mumbai, India
    Posts
    6

    Assertion in _CrtIsValidHeapPointer().

    hi gurus,
    I have a strange problem. I have a COM dll. This COM dll has settings as "Multithreaded" for release and "debug Multithreaded" for debug version. I have a test application which hosts this dll as an INPROC server. In the dll, i create a pointer to a class using new. I delete it immediately in the next line. Here, on delete, I get an assertion in _CrtIsValidHeapPointer()! which says that the memory address does not belong to local heap. If i am deleting immediately after new, why should this problem come?
    e.g. The dll function looks like this.

    STDMETHODIMP CData::Write(IStream *pStream)
    {
    // class defined in another lib statically linked to this dll.
    CMyClass *pMyClass = new CMyClass;
    delete pMyClass; // Assertion at this.
    }

    Interestingly, if i create a pointer to the same class using new in Test application and delete it , it works fine. So there seems some problem within the dll. Can anyone throw some light on this??

    thanx in advance!

  2. #2
    Join Date
    Jun 1999
    Location
    San Diego, CA
    Posts
    600
    This assertion failure tells you that you are attempting to deallocate memory that was allocated in a different heap space, so although the pointer is the same, they are not pointed to the same memory!!!

    Further, this mean the allocation and deallocation of a piece of memory happens in different executable modules. Look at what you do in the constructor and destructor of your class, and where you do it.

    Also, if different modules uses different settings for CRT (debug, debug multi-threaded, debug multi-threaded DLL), the described problem may occur. It is best to consistently use debug multi-threaded DLL for all modules.

  3. #3
    Join Date
    Jun 1999
    Location
    San Diego, CA
    Posts
    600
    Here is what the comment in the CRT source code says about
    this assertion:
    Code:
    /***
    *int _CrtIsValidHeapPointer() - verify pointer is from 'local' heap
    *
    *Purpose:
    *       Verify pointer is not only a valid pointer but also that it is from
    *       the 'local' heap. Pointers from another copy of the C runtime (even in the
    *       same process) will be caught.
    *
    *Entry:
    *       const void * pUserData     - pointer of interest
    *
    *Return:
    *       TRUE - if valid and from local heap
    *       FALSE otherwise
    *
    *******************************************************************************/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured