[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

03/08/2006 at 07:08PM PST, ID: 21766511
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

double free or corruption

Asked by chsalvia in C++ Programming Language

Tags: free, double, corruption

I'm getting this error at runtime:

*** glibc detected *** double free or corruption (fasttop): 0x0804a008 ***
Aborted

This happens when an instance of one class encapsulates and assigns an instance of another class.

I tried to narrow down the problem using a debugger, and it seems the error is produced because somehow I call delete[] on an already deleted pointer in the class destructor.  At least, I think that's the problem - but I'm not sure HOW that's happening.  I was finally able to create a very simplified test program that reproduces the exact problem so I could post it here without posting hundreds of lines of code.  Here it is:

// BEGIN CODE

class Buffer
{
      char* buffer;
      int len;

      void init(char* str)
      {
            len = strlen(str);
            buffer = new char[len+1];
            memcpy(buffer,str,len);
      }

      public:
            Buffer(char* str)      { init(str); }

            ~Buffer() { delete[] buffer; } // <--- this destructor is causing the problem, but why?
      
};

class Class2
{
       Buffer buf;

      public:
            Class2(Buffer& buffer) : buf(buffer) { }
            ~Class2() { };
};

int main()
{
      Buffer buf = "abcdefghijklmnopqrstuvwxyz";
      Class2 c2(buf);
}

// END CODE
[+][-]03/08/06 07:24 PM, ID: 16141206

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/08/06 07:27 PM, ID: 16141218

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03/08/06 07:28 PM, ID: 16141220

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/08/06 07:29 PM, ID: 16141227

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/08/06 07:30 PM, ID: 16141232

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/08/06 07:30 PM, ID: 16141235

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/08/06 07:32 PM, ID: 16141244

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C++ Programming Language
Tags: free, double, corruption
Sign Up Now!
Solution Provided By: rajeev_devin
Participating Experts: 4
Solution Grade: A
 
 
 
Loading Advertisement...
20091028-EE-VQP-87