Solved

Invalid Address specified to RtlValidateHeap

Posted on 2004-04-22
8
1,219 Views
Last Modified: 2008-02-01
Hi,

I've made a screensaver, which when closed under debug mode of VC6 brings up a messagebox with

"User breakpoint called from code at 0x77f75a58"

In the debug window it says..
HEAP[IntelliScreenSaver.scr]: Invalid Address specified to RtlValidateHeap( 00870000, 0087303C )

I was just wondering what all that meant? Memory leaks? And if so is there anything I can do to track down the errors? It's closed by using PostMessage(WM_CLOSE, 0, 0l); (that was there in the framework I started with)

Thanks
0
Comment
Question by:shifty_mc
  • 3
  • 3
  • 2
8 Comments
 
LVL 13

Accepted Solution

by:
SteH earned 60 total points
Comment Utility
This means that a variable which you are trying to free does not belong to the heap (anymore?) It can happen if you try to deallocate memory twice. Set pointers to 0 after deallocation a it should be safe if you are using new and delete.
delete 0;
does nothing.
0
 

Author Comment

by:shifty_mc
Comment Utility
Oh, well that was simple - deleted a line in the OnDestroy method saying
delete currentplugin;
and no more errors.

I'm confused tho - I haven't deleted it elsewhere - where's it gone?

currentplugin is a pointer to a class derived from CPlugin which is created at runtime, although it's not created with new directly...
currentplugin = CPlugin::GetCurrentPlugin(m_plugin);
and in my CPlugin class I have
CPlugin* CPlugin::GetCurrentPlugin(CString &TypeName)
{
      if (TypeName == "sometype") return new CSomeclass();
      ...
      return NULL;
}

thanks
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 60 total points
Comment Utility
This means CPlugin class deletes itself somewhere. Try to search it's source code for "delete this". Try to set breakpoint in your CPlugin-derived class destructor and see that it is called (this means, you don't have memory leaks) and from where.
0
 

Author Comment

by:shifty_mc
Comment Utility
Hmmm, no "delete this", apart from in my main class.

I'm not normally a c++ programmer, and I've got memory leaks all over the place - without the "delete currentplugin" though I don't get the messagebox, but get a list of memory leaks in the debug window.

Where should my delete's go then? And why is the delete currentplugin not working? I tried putting a breakpoint on the CPlugin derived destructor, and no change in the debug window - I take it that means it isn't called? This is by far the biggest thing I've done in C++/VC6 so haven't really used the debugger/breakpoints before.
0
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!

 
LVL 13

Expert Comment

by:SteH
Comment Utility
In VC6++ I get memory leaks from time to time which are not real leaks. Memory allocated during CRT startup is not released when the memory checking occurs but gets deleted later on. This is displayed as leaking memory.

You can put

static struct _test
{
    _test ()
    {
        _CrtSetBreakAlloc (1689); // change the number to one you find for a source of leak {xxx}.
    }
} test;

into your code to see where the allocation occurs and whether it should have been deleted already.
0
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
OK, my guess was wrong. Set breakpoint in the line

delete currentplugin;

and check value of "this" and value of currentplugin - is it equal to initial value of this pointer when object was created.

By the way, you can use breakpoints only if you run program under debugger - Go command and not Run.
0
 

Author Comment

by:shifty_mc
Comment Utility
Arrgh!

It was just something very simple... in my CPlugin class I had an array of strings created with new, that I had been deleting with a plain old delete instead of delete[]. When I changed that it solved everything. No more memory leak notifications or message boxes!

Thanks for your time.

SteH - I put your code in before I noticed that error - but am unsure what it actually does. When I used it, it didn't seem to change anything. I didn't pay too much attention tho it has to be said - noticed where I was going wrong soon after.

I'll split the points evenly, cheers.
0
 
LVL 13

Expert Comment

by:SteH
Comment Utility
The code allows you to break on memory allocations which occur early during the program. If you put the line
_CrtSetBreakAlloc (1689);
in a file using MFC it is best placed in the CWinApp derived class constructor or init. But a lot of allocations happened already at that time. I had notifications about leaks with numbers like 70 and could not find them before. Using that approach I found that the allocations was done for some constant strings. Not allocated using malloc or new so no need to release them. But when the check for leaks was done these were reported. But they could be safely ignored.

But happy that you found your problem anyhow.
0

Featured Post

Highfive Gives IT Their Time Back

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

772 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

10 Experts available now in Live!

Get 1:1 Help Now