Solved

"pure virtual function call" - heap error

Posted on 2013-01-29
15
641 Views
Last Modified: 2013-02-22
Hi Experts,

I'm getting this heap error in release mode.  I can't reproduce it when trying to make application verifier watch the heap - it interferes with the path of the code in memory too much in my case I guess.  I'm very rusty on how these tools are used- can anyone give me a quick summary of what I need to do to find the offending code causing this?

Thank you!
Mike
0
Comment
Question by:thready
  • 7
  • 3
  • 2
  • +3
15 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
ID: 38833903
This one http://msdn.microsoft.com/en-us/library/fsk896zz%28v=vs.100%29.aspx ("How to: Debug a Release Build") might help...
0
 
LVL 32

Assisted Solution

by:phoffric
phoffric earned 100 total points
ID: 38834020
Works in debug mode but not in release mode often indicates a memory or likely a pointer problem. These tools should solve the problem quickly for you once you understand how to reject the false positives.

IBM Rational Purify (This link has a trial offer):
     http://www-01.ibm.com/software/awdtools/purify/win/

Parasoft Insure++
    http://www.parasoft.com/jsp/products/insure.jsp?itemId=63

I know that Parasoft used to give a 2-4 week free trial evaluation. I used Insure++ on SCO Unix and Windows (integrated into Visual Studio), and it probably saved us at least 1 man year when upgrading our OS. The software had been tweaked to give good results without deep understanding of erroneous code. Insure++ pointed out 100's of issues for them.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 38834025
I found this comparison of Purify vs Insure++. Not sure how old it is and whether the comparison holds. But the link is good in that it gives you and idea of some of the errors that these products can detect in run-time environment. (I know Insure++ also has extra compile time useful errors generated, but its main value is in run-time diagnostics.)
    http://char.tuiasi.ro/doace/www.parasoft.com/products/insure/compare/examples.htm
0
 
LVL 1

Author Comment

by:thready
ID: 38835485
Thanks gentlemen, looking into your answers now! :)
0
 
LVL 1

Author Comment

by:thready
ID: 38835537
No luck with the release mode build jkr- I still get the "pure virtual function call" runtime error.  I can see that it's within a basic_string copy and there's a stack trace with no indication of where i'm at... but at this point, I'm passed where the problem occurs.

phoffric- I just created a profile and requested an insure++ eval.

I'm a little surprised no one told me to use windbg for this.  I was hoping that you would (so I could ask you how to use it for a heap error!)- is it because it's tough to use? :)
0
 
LVL 1

Author Comment

by:thready
ID: 38835551
Actually jkr- I noticed this in the output line in my release build with debug info generated:

"First-chance exception at 0x75ddc41f in Knee3DAssessment.exe: Microsoft C++ exception: Poco::NotFoundException at memory location 0x0018fbb4.."

This looks to me like Poco is trying to access memory that has been corrupted, right?  Anything I can do with this to figure out where the offending code is?
0
 
LVL 1

Author Comment

by:thready
ID: 38835591
More info:  just got this in the output window while using application verifier (any idea how to use these addresses?)

First-chance exception at 0x004d18d0 in my.exe: 0xC0000005: Access violation reading location 0x09fd5f58.


===========================================================
VERIFIER STOP 0000000000000013: pid 0x16DC: first chance access violation for current stack trace

      0000000009FD5F58 : Invalid address being accessed
      00000000004D18D0 : Code performing invalid access
      000000000008DC60 : Exception record. Use .exr to display it.
      000000000008D770 : Context record. Use .cxr to display it.
===========================================================
This verifier stop is continuable.
After debugging it use `go' to continue.
===========================================================



=======================================
VERIFIER STOP 00000013: pid 0x16DC: First chance access violation for current stack trace.

      09FD5F58 : Invalid address causing the exception.
      004D18D0 : Code address executing the invalid access.
      0018F7DC : Exception record.
      0018F82C : Context record.


=======================================
This verifier stop is continuable.
After debugging it use `go' to continue.

=======================================
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 22

Assisted Solution

by:ambience
ambience earned 100 total points
ID: 38835730
>> This looks to me like Poco is trying to access memory that has been corrupted, right?  Anything I can do with this to figure out where the offending code is?

Unless theres another instance of it, it just tells that the exception was thrown. First chance exceptions are normal behavior.

With these kind of crashes theres no single way that always works, you can try various different things and get hints leading you to the real cause. In addition to external tools internal application logs (if you have) are really helpful in figuring out a pattern of execution that leads to crash and careful code review along those paths often helps.

Windbg can also help - If you have the pdbs for the release mode then let your program crash and depending on your version of windows you can either use DrWtsn32 to create coredump or other tools (cant remember but latest Windows versions have registry settings to enable coredump creation - you can search google for how to setup coredump creation).

That coredump can be loaded into WindBg and as long as the pdb matches it should give an idea of the location and type of exception - the variables window also works as well as callstack.
0
 
LVL 86

Expert Comment

by:jkr
ID: 38835933
>>any idea how to use these addresses?

Build your application with 'Generate Map File' enabled. Using that map file, you can look up the address to see in which function/method that happened.
0
 
LVL 1

Author Comment

by:thready
ID: 38836124
points coming soon.  Boss just put me on something else urgent.  Thank you very much for your comments- I'll come back as soon as I can!
0
 
LVL 4

Assisted Solution

by:havman56
havman56 earned 100 total points
ID: 38839349
int CrashReportingFunction( int reportType, char *userMessage, int *retVal )
{
......
return true;
}


immediately after your main() please install crash hook like this

_CrtSetReportHook( CrashReportingFunction );

when you register crash report function , when invalid memory access happens then this function will get triggered ., you can print whatever you like debug info
0
 
LVL 32

Accepted Solution

by:
sarabande earned 100 total points
ID: 38850927
in case of access violation error, first chance exception handling is not normal behavior. it only means that the usage of a pointer was handled by  a try-catch block. windows does that for example when it calls a function pointer stored with a window for message processing. in case the pointer is not (or no longer) valid the exception was caught (first chance) and it would ignore the error.

however such handling does not solve a problem. it only could be a work-around in case a programmer was not able to handle asynchronous or multi-threaded processing in the correct order and when the code that leads to the exception actually was not needed (at that time). in your case where the program is crashing after the first chance exception, it is much likely that the wrong pointer was used later again but outside of a try block or points to corrupted memory where there is no way out.

the problem with first-chance exceptions is that the actual pointer access (which went wrong) was not revealed because of the exception handling. in debug mode you could help from that in visual studio by a setting. go to menu entry debug\exceptions ... and navigate to win32 exceptions\access violation. here you can check a box which makes the debugger break immediately when the exception was thrown, what means that it breaks regardless whether the exception was handled or not. i hope that this behavior also would work for your release build with debug information.

Sara
0
 
LVL 1

Author Comment

by:thready
ID: 38860689
I'm still looking into this- thanks for all the great comments everyone.  Trying to get my hands on trials of purify and insure as well...  Insure++ is tougher to get - and purify doesn't show the problems found with evaluations...
0
 
LVL 32

Expert Comment

by:phoffric
ID: 38860965
I believe that in the next few weeks I will be using Purify. Insure++ used to be easy to get for an evaluation. It is a great product. It will be nice to compare with Purify.
0
 
LVL 1

Author Closing Comment

by:thready
ID: 38919471
Thanks everyone
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

747 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

18 Experts available now in Live!

Get 1:1 Help Now