[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

HEAP[.exe]: Invalid Address specified to RtlValidateHeap( 00350000, 0115E000 )

Posted on 2005-05-05
13
Medium Priority
?
967 Views
Last Modified: 2013-11-20
Hi

again I have troubles with the heap!

I have a CView class. In OnInitialUpdate() I create a new CRecordset class (on the heap)
it is only destructed in the destructor of the CView class.

I have a message handler - OnRefreshWindow which is called when the
application views are switched. This handler uses the recordset to requery for a specific
record.

On the initial swith to this view everything is working fine - everytime.

On sometimes second and more often third switch to this view, I get the error


HEAP[Acquisition.exe]: Invalid Address specified to RtlValidateHeap( 00350000, 0115E000 )

I trace this to my message handler and a call to rs.Requery();
tracing into requery, the problem occurs in CRecordset::Close()

line 1152: delete [] m_rgODBCFieldInfos;

In my code I can find nowwhere where I have overwritten the memory for the recordset
and this problem only started to happen now.

Can anyone help?

Thanks
anti
0
Comment
Question by:antinutrino
  • 8
  • 3
  • 2
13 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13936579
line 1152: delete [] m_rgODBCFieldInfos;
In my code I can find nowwhere where I have overwritten the memory for the recordset

Overwritten memory doesn't cause such error, sound like you have deleted with the same pointer previously.

Maybe you can put some instructions to test:

if (!m_rgODBCFieldInfos)
     ::AfxMessageBox ("Trying to delete NULL pointer!");
else {
     delete [] m_rgODBCFieldInfos;
     m_rgODBCFieldInfos=NULL;
}

Also, ensure to initialize your pointer to NULL in your constructor.
0
 

Author Comment

by:antinutrino
ID: 13936655

Pointer is initialised in Constructor to NULL
Breakpoint on Destructor and OnInitialUpdate()
these functions are only entered once.

if (!m_rgODBCFieldInfos)
     ::AfxMessageBox ("Trying to delete NULL pointer!");
else {
     delete [] m_rgODBCFieldInfos;
     m_rgODBCFieldInfos=NULL;
}


where might I put this code?


THanks
anti
0
 

Author Comment

by:antinutrino
ID: 13936701
Hi

I just made my recordset an object instead of pointer and the same thing
is happening.

???

confused
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13936735
How are you switching views? There are many techniques, a view is destroyed every time you switch, or just hides?
0
 

Author Comment

by:antinutrino
ID: 13936770
The views are only created once. and I just show or hide the appropriate one. There are
over views using the same techniwue with the recordset that do not have this problem
but i cannot find the difference!

Thanks
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 1400 total points
ID: 13936855
Try to explicity close all you data (like recordsets and database) at the very first part of your destructor.
But, there is some strange, data must not reside in view but in doc object according with doc/view model....
0
 

Author Comment

by:antinutrino
ID: 13936891
Hi

the destructor is never called in the scenario given.
I will look at the doc/view issue you mention but I have other view doing the same thing.
this is very strange, and the timing of the problem is just great as usual!

Many thanks
anti
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 600 total points
ID: 13937690
How are you allocating the memory? That error is typical for memory allocated e.g. in a DLL and deleted in the .exe.
0
 

Author Comment

by:antinutrino
ID: 13938203
Hi

Constructor
{
m_pdbMonitor = NULL;
}

Destructor
{
if (m_pdbMonitor != NULL) {
      if (m_pdbMonitor->IsOpen())
             m_pdbMonitor->Close();

      delete m_pdbMonitor;
}
}


OnInitialUpdate()
{
       m_pdbMonitor  = new CDBMonitor(GetDatabase());
       // --- open the recordset
       ......
}

// this is called each time the view is displayed or switched to
OnRefreshWindow()
{
      // Get document
      m_pdbMonitor->m_strFilter.Format("id = %d", pDoc->GetID());
      m_pdbMontior->Requery();                                                    // crash is here on second or third switch
}

The destructor is never called. No other functions in the code allocate, deallocate or even
close the recordset.

As I said I have another view doing the same thing and it works every time.
The view in question also used to work!!!!

argh!

Thanks
anti
0
 

Author Comment

by:antinutrino
ID: 13938391
> How are you allocating the memory? That error is typical for memory allocated e.g. in a DLL and deleted in the .exe

The DBClasses are contained in a DLL.
0
 
LVL 86

Expert Comment

by:jkr
ID: 13938936
>>The DBClasses are contained in a DLL.

Is

line 1152: delete [] m_rgODBCFieldInfos;

also in that DLL? If not, this is most likely to be the problem.
0
 

Author Comment

by:antinutrino
ID: 13939136
Hi

All the DBClasses are derived from CRecordset and all reside in the
DLL file, so I guess this line must be in the DLL.

Another thing is that when I look at the state of the member variables for the
recordset before calling Requery, they are all in good state. No "error expression
cannot be evaluated", so is this a memory allocation problem?

I did a work around where I removed the allocation from
on initial update to when the view is "switched to" and close and deallocate
the recordset when the view is hidden, this works!

I guess this suggests that is is a memory problem?

what a hum dinger!

Many thanks
anti

0
 

Author Comment

by:antinutrino
ID: 13955002
Hi

It seems my workaround was also having some unpredictable results.

I moved all the recordset initialisation to the Document class (as suggested
by jamie_olivaries) and used DeleteContents to free the memory and it now
works, no crashes.

Thanks
anti
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

865 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