Question

HELP!!!!!! IsValidHeapPointer

Asked by: TheShark8

Hi,
I have an application that running all the time.
sometimes the application crashes and I get this error (in debug assertion) : dbgheap.c
"_CrtIsValidHeapPointer(PUserData)"
what does this error means?
what could cause this problem?
I have no clue cause sometimes it happens and sometimes it doesn't.
thanks,
TheShark.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-02-23 at 04:10:46ID20525769
Tags

crtisvalidheappointer

,

isvalidheappointer

Topic

C++ Programming Language

Participating Experts
5
Points
50
Comments
12

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. CSingleLock Debug Assertion
    I added a CMutex object to some code I was writing. Occasionaly I get a Debug assertion on the ASSERT(!m_bAcquired) in the CSingleLock::Lock() m_bAcquired is 0 when the error occurs and the class looks like everything is in order. This happens intermittantly and sometimes...
  2. Assert error on strcore.cpp
    When I was try connect with socket, Visual C++ SP6 giving assertion error. What is the solution? Debug Assertion Failed! Program:D:.................\BULKMAIL.EXE File:strcore.cpp Line:154 Abort Retry Ignore sometimes Line:53
  3. CListCtrl  "Debug Assertion Failed"
    I tried a few examples already from the MFC book I am reading and everything worked. I try to work the same steps into my app and I get the following. "Debug Assertion Failed File afxcmn.ini Line 148" The app compiles fine without any errors but as soon as I laun...
  4. Assertion Debug Error in dbgrpt.c
    Hi, I am writing a network program and using winsock and threads and stuff. I got this error tell me of Assertion Debug Error then it shows me the code in a file named dbgrpt.c in the function _CRTIMP int __cdecl _CrtDbgReport( int nRptType, const char * sz...
  5. vc++ debug assertion error
    help :\ Debug Assertion Failed! Program: ...\DAPP\DEBUG\DAPP.EXE File: appcore.cpp Line: 85 & Program: ...\DAPP\DEBUG\DAPP.EXE File: appcore.cpp Line: 92 any thoughts? -mare mortis (oops, didn't mean to post this here, still need help though)
  6. help with debug assertion failure
    If I build my MFC activeX control as Win32 Release and test the control with ActiveX Control Test Container, the control works fine...no crashes or anything. If I bulit the same control as Win32 Debug, in the Test Container I get a debug assertion failure. Error: "The...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: bodokePosted on 2003-02-23 at 04:34:01ID: 8002661

It means you have a pointer/memory problem somewhere in your application. For example, if you delete a dynamically allocated block of memory twice, the second will fire the assert.
The error means you are doing something to a pointer to heap memory which is no longer valid.

 

by: nietodPosted on 2003-02-23 at 04:56:08ID: 8002704

right.  

Other possible causes (other than deleting the same memory twice) would include trying to delete memory that was never allocated, like

const char *AString = "abcdef";

delete [] AString;

or deleting a pointer that is not a pointer to the _start of_ a dynmically allocated block.   Like

char *AString == new char [10];

for (int i = 0; i < 5; ++i)
   *AString++ == 'a';

delete [] AString;

(This alters AString so it points to a character in the middle of the allocated memory, not the start, so the delete fails.)


When you get this alert, you will be inside a procedure in the C++ runtime library.  i.e. not a procedure you've written.  But that procedure is called (ultimately) from code you've written.  you should look at the call stack (in the variables window).  It lists the procedure you are currently in, the procedure that called that one, the procedure that called that one and so on until main (the bottom of the call stack).  So look through the call stack until you find a procedure that you wrote.   Look at that procedure, its likely the problem is there.  (That procedure shoudl be calling delete, delete [] or free().   If the pointer that procedure is trying to delete with is passed to that procedure, then the problem might be in the procedure that calls it.  Again you might have to move down the call stack until you reach a procedure that is really responsible for the problem.

 

by: grg99Posted on 2003-02-23 at 08:41:12ID: 8003416

What I've done in hard cases where there's soem kind of pointer error, I write wrappers for malloc and free.

The wrapper for malloc makes sure the real malloc returns a non MLL pointer, and it enters the pointer in a table of valid pointers.

Our free(0 wrapper does the reverse, it makes sure we're not freeing NUL, plus it checks that what we're freeing is in our valid malloc'ed pointer table.

I've found scads of bugs this way..

Regards,

George

 

 

by: nietodPosted on 2003-02-23 at 09:08:55ID: 8003526

why bother?  That is what VC is already doing (in effect).

The debug version of the VC RTL checks ever pointer passed to delete or free to make sure it is a valid heap pointer.  In this case it is not and it is reporting that error.  Another mechanism that would detect the error isn't needed.  We know there is an error.  Now you need to find the cause.

 

by: bkrahmerPosted on 2003-02-26 at 23:25:29ID: 8031632

I would just like to state that code should not contain asserts.  99% of the time, anyway.  A better solution is to use test-first-design.  The test cases are there, the interface is well-established, and you have tests to fall back on if you want to change the code.  Give it a try, and I bet your pointer problems will disappear.
brian

 

by: nietodPosted on 2003-02-27 at 04:09:47ID: 8032882

>>  would just like to state that code should not contain asserts.  99% of the time, anyway.
That's nonsense.    asserts are an extremely useful method for performing testing.   In particular, asserts excellent for performming invariance testing and parameter testing.

furthermore, this assert is inside the C++ RTL.  Its not like TheShark8 can remove it.  And the VC programmers obviously think that asserts are useful.  And they are.  In this case, they are using it for parameter testing....

 

by: bkrahmerPosted on 2003-02-27 at 08:59:31ID: 8034973

Goto statements are useful.  So are having multiple return statements in one function.  Something that is useful does not necessarily imply that it's the best way to do something.  Besides that, aborting a program because of one improperly passed variable is a very bad decision most of the time.  If I did that in my enterprise application that is supposed to be running 24/7, where does that leave me?  This is C++, is it not?  There should be specific return values for bad parameters, or structured exception handling used, not asserts.  In addition, I have seen people use asserts as reminders of smelly code where an assumption was made and the function was not really finished.
brian

 

by: nietodPosted on 2003-02-27 at 09:29:02ID: 8035223

>> Besides that, aborting a program because of one improperly passed
>> variable is a very bad decision most of the time.  If I did that in my
>> enterprise application that is supposed to be running 24/7, where
>> does that leave me?
I don't think you understand assert().   Its a testing and debugging too.   An assert() won't even be present in a released application--unless you make some unusual choices.

an assert or similar procedure is not only a good way of testign for certain types of errors it is simply the ONLY way to test for them.  That is why its use is so important to library designers.  And that is why you see it used in the VC library.  Think about it.   No matter how much testing some library programmer does, no mattter what he/she decides to do.  There is NO way to prevent a client from calling a library procedure with incorrect parameters.  Only debug-time testing can be used to detect this sort of problem.

>>  There should be specific return values for bad parameters, or
>> structured exception handling used, not asserts
Either would be invalid for this case, since delete cannot return a value or throw an exception.

If you are concerned about the life of your program in this case, the assert only notifies the debugger of the problem, that is all.  If there is no debugger, there is no alert.  And if this occurs under a typical release version, there is no assert code (its conditional code.)  And in either case VC handles the problem as elegantly as possible--basically it ignores it.  That is about the best that can be done.   Throwing an exception to tell you that memory got corrupted is almost pointless.  There is no possible way to catch the exception and do something useful about it!  that same would be true about a double delete or a delete of an invalid pointer.  If you threw an exception, most programs would either be terminated by the exception, or catch it and ignore the problem.  Neither is better than VC's choice.  

And yes there are many times when a library procedure can inform the caller of an error and where the caller can often take reasonable action.  But that is not always the case.

>> In addition, I have seen people use asserts as reminders of smelly
>> code where an assumption was made and the function was not
>> really finished
I have seen programmers that have abused the use of classes, but I'n not going to stop using them either.

 

by: bkrahmerPosted on 2003-02-27 at 18:58:26ID: 8038910

Nietod, picking apart my argument is not adding anything to this topic.  I did forget the fact that asserts are conditionally compiled.  Which leads me pointing out that your statement of 'an assert or similar procedure is not only a good way of testign for certain types of errors it is simply the ONLY way to test for them' is bogus.  There is only one way to skin this cat, and that is code that will only do checking in debug versions of the code?  If it's worth checking in debug mode, it's absolutely worth checking in release mode, IMO.  You are correct in stating that throwing an exception to tell you memory is corrupted is pointless.  Kind of like using CrtIsValidHeapPointer, isn't it?  The whole point of my initial post was mentioning test-first design, and you completely glossed over it.  There are problems like handling memory that cannot be easily solved in a fool-proof way.  However, with good coding practices, they can be nearly eliminated.
brian

 

by: nietodPosted on 2003-02-28 at 04:19:14ID: 8041116

>> If it's worth checking in debug mode, it's absolutely worth checking in release mode, IMO
Yes.  and VC does.  I only reports the error in debug mode.  

>> You are correct in stating that throwing an exception to tell you memory is
>> corrupted is pointless.  Kind of like using CrtIsValidHeapPointer, isn't it?
Not really.  VC uses CrtIsValidHeapPointer (or its equivalent) to make sure it doesn't corrupt the heap--or at the very least to not further corrupt it.  i.e. even in a release mode it won't "delete" a block that determines is not really an allocated block.  

Some programmers further use CrtIsValidHeapPointer() in their production code to differentiate between allocated blocks and non-allocated blocks.  i.e. you pass can pass a pointer to a procedure or class and if it is for an allocated block, it will eventually be deleted, otherwise not.  A debatable choice, but its done nevertheless.   (not much of a debate really)

>> The whole point of my initial post was mentioning test-first
>> design, and you completely glossed over it.
That is great, but its not of any value to the programmer that put in that assert.  he/she could never test for this error.

 

by: bcladdPosted on 2003-11-19 at 18:16:57ID: 9784249

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered: Points split between bodoke and nietod

Please leave any comments here within the next seven days. Experts: Silence
means you don't care.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...