Invalid Address specified to RtlFreeHeap on Destructor
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Invalid Address specified to RtlFreeHeap on Destructor

  1. #1
    Join Date
    Apr 2009
    Posts
    47

    Invalid Address specified to RtlFreeHeap on Destructor

    I am trying to preserve the original value of an object for use at each iteration of a loop, however on when the elements are deleted which are only in scope of the loop, I get an error which says: "Invalid Address specified to RtlFreeHeap." I can't figure out what I am doing wrong.

    Here is a sample of my code:

    Code:
    	void mainTest (Graph_ptr _dataGraph)
    	{
    		Graph originalDataGraph = (*_dataGraph);
    
    		for(int i=0; i<10; i++)
    		{
    			Graph dataGraphCopy = originalDataGraph;
    			Graph_ptr dataGraph = Graph_ptr(&dataGraphCopy);
    
                            // do some other things
                    }
            }
    Note this code works properly if I change the dataGraph definition to:
    Code:
    Graph_ptr dataGraph = _dataGraph;
    However, by doing this, I lose the original value of the dataGraph which I need at the start of each loop iteration. Also, Graph_ptr is just a boost pointer of type Graph.

    What could be the problem?

    Thanks.

  2. #2
    Join Date
    Oct 2008
    Posts
    1,168

    Re: Invalid Address specified to RtlFreeHeap on Destructor

    Quote Originally Posted by NTL View Post
    Graph_ptr is just a boost pointer of type Graph.
    do you mean a boost::shared_ptr ? if yes, in the line "Graph_ptr dataGraph = Graph_ptr(&dataGraphCopy);" you are constructing a shared pointer from a pointer to an object on the stack.

    instead of

    Code:
    Graph dataGraphCopy = originalDataGraph;
    Graph_ptr dataGraph = Graph_ptr(&dataGraphCopy);
    you should write simply

    Code:
    Graph_ptr dataGraph( new Graph( originalDataGraph ) );
    or

    Code:
    Graph_ptr dataGraph = boost::make_shared<Graph>( originalDataGraph );
    anyway, the way you code makes me think you might not have a proper understanding of C++ basics ( and boost smart pointer library for what matters ). I say this because coding this way in C++ is dangerous and it inevitably leads to unstable/buggy programs even when they appear working as expected. Just a friendly warning ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center