Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6998911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:28:19+00:00 2026-05-27T20:28:19+00:00

I have a class named Packet with this destruct: class Packet { … RequestPtr

  • 0

I have a class named “Packet” with this destruct:

class Packet
{
   ...
   RequestPtr req;
   ~Packet()
   {
     if (req && isRequest() && !needsResponse())
        delete req;      
     deleteData();
   }
};

The RequestPtr looks like:

typedef Request* RequestPtr;
class Request
{
   ...
   ~Request() {} 
}

Problem is when delete req; and consequently ~Request() {} are executed, I get this error:

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

At first I thought that maybe req were deleted somewhere else and when it want to execute delete req;, obviously there is no req. However as you can see, there is a if statement which checks if the req is defined or not. So definitely when it want to delete req, the object is defined.

What does this error really mean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:28:19+00:00Added an answer on May 27, 2026 at 8:28 pm

    The default copy constructor and assignment operator are used in class Packet and you have a pointer to dynamically allocated memory.

    If a copy of Packet is made and the original object destroyed a double deallocation will occur when the second object is destroyed. Either implement the copy constructor and assignment operator or prevent copying of Packet by declaring them private.

    The check if (req) will be true if req is not NULL, not if it has already been deallocated (as stated by Mat in comment to question).

    If you delete req in some other method of the class you must set req to NULL:

    delete req;
    req = 0;
    

    Or a double deallocation will occur.

    Just to note that calling delete on a NULL pointer has no effect, so the following is safe:

    delete req;
    req = 0;
    delete req; // No need to check 'if (req)'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class named baseClass. From this class I inherit a class names
I have a class named Person and in this class is the property PersonName
Say I have a class named Frog, it looks like: public class Frog {
I have a class named Graph, in this class I have a member named
I have an class named Foo. This class contains a collection of child objects
I have classes which are inherited from abstract Packet( this class has abstract method
I have a class named MyClass and I want this class to extend Graphics2D
I have a class named myClass. This class has TouchesMoved and TouchesBegan defined. This
I have a class named dot and many instances of this same class are
i have class named Group i tried to test configuration: var cfg = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.