std string user breakpoint called, _CrtIsValidHeapPointer

Posted on 2006-05-14
Last Modified: 2013-12-14
Hi guys,

I've got a simple console app in VC6 that uses stl strings.
Whenever a string gets destroyed, I get an abort.
Looks like the heap pointer doesn't exist anymore...

I've seen other postings with similar issues, however none of those solutions helped :(

The app is a simple oracle OCCI application.
As soo as I make a call to get a string from a resultset, and the resulting string gets popped off the stack, the abort occurs.
I.e. right after

I'm not mixing old std C++ and ansi std C++, so that shouldn't be the problem.

Projects options:
I tried 'Mulithreaded DLL' (/MD) , 'Debug Multithreaded DLL' (/MDd) and 'Debug Multithreaded' (/MTd) to get the program to link with the right libs.
Question by:Jaco_Kruger
    LVL 8

    Expert Comment

    I've never noticed any problem with strings in ATL (VC 6.0).
    What is "getString()", is it your method ?
    LVL 8

    Expert Comment

    getString() - how is it implemented ?
    LVL 86

    Expert Comment

    >>Whenever a string gets destroyed, I get an abort.

    You are returning the string from a DLL or mixing debug/realease modules? If so, you encountered that memory has to be freed in the module it was allocated in. Passing template classes (such as a std::string) over module boundaries is not a good idea for these reasons.

    Author Comment

    getString is a method inside an oracle library that i link statically to (oraocci9.lib).
    According to Oracle documentation the signature is 'string getString(int);'
    So it always creates a new string object upon returning.
    I'm compiling my code in debug mode on windows and we use a release version for unix platforms. But can mixing a release library with debug code cause the heap to become corrupt?
    LVL 86

    Accepted Solution

    >>But can mixing a release library with debug code cause the heap to become corrupt?

    You aren't experiencing a corrupted heap. Debug and Release versions use different heaps, each has their own. If you try to deallocate memory in Debug that was allocated in Release, the pointer is invalid for that heap that tries to free it. If you run all modules either as Debug or Release (with '(Debug) Mulithreaded DLL'!), there shouldn't be a problem.
    LVL 1

    Expert Comment


    i have done these things with excel sheet , db connection with excel sheet
    using com object of ado in c++ .. if i m not making any mistake that is what ur doing with oracle..

    just go throgh the following link
    see the get method defined in the sample u will get ur ans..

    if its useful let me know

    Author Comment

    Jeez, Got it fixed.
    Added msvcprt.lib in my 'inclusion' library list, and
    added libcmtd.lib in my 'ignore' library list.

    Looks like even though I'm compiling debug code, I have to link with msvcprt.lib (which is the release version), if I'm using an external (release version) library like oraocci9.lib.

    jkr gets it for being closest ;)

    Thanks guys.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
    Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall‚Ķ
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now