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

  • SEARCH
  • Home
  • 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 6913283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:11:55+00:00 2026-05-27T09:11:55+00:00

The problem I’m getting is that I’m getting heap corruption messages during deletion of

  • 0

The problem I’m getting is that I’m getting heap corruption messages during deletion of binary tree nodes. The message says:

HEAP[lab4.exe]: HEAP: Free Heap block 5788c0 modified at 5788e8 after
it was freed Windows has triggered a breakpoint in lab4.exe.

This may be due to a corruption of the heap, which indicates a bug in
lab4.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while lab4.exe has
focus.

It sounds like I’m writing to a block of memory that has been freed. Valgrind seems to confirm this with messages like:

Invalid write of size 4

at 0x8049C65:> BinTree::removeTree(BinTree::Node*) (in/net/metis/home2/alexo2/lab4/a.out)
…
==9681== Address 0x402ab50 is 0 bytes inside a block of size 12 free’d

at 0x40054B4: operator delete(void*) (vg_replace_malloc.c:346)
by 0x8049C61: BinTree::removeTree(BinTree::Node*) (in
/net/metis/home2/alexo2/lab4/a.out)

…

When I trace through the program, the heap corruption messages begin usually in a parent class or base class destructor. I’ve been trying to trace this but I have no idea where the problem is. I never use delete on these nodes until the destructor.

I suspect the problem has something to do with the way I’m deleting or keeping track of the binary tree. Here’s some code I’ll post, not sure if it will help with finding a solution.

So, a class object is dynamically allocated and returned by a function. This object is kept track of with pointers until it finally is inserted into the node of a binary tree.
At the end of the program when everything is being deleted, the destructor is called:

void BinTree::makeEmpty()
{
    if ( root != NULL ) {
        removeTree( root );
    }
    root = NULL;
}

void BinTree::removeTree( Node *curr )
{
    if ( curr == NULL )
        return;

    removeTree( curr->left );
    removeTree( curr->right );

    delete curr->data;
    delete curr;

    curr->data = NULL;
    curr = NULL;
}

In some function, this is the call that creates and returns the dynamically allocated object:

Item *aMovie = factory.createMovie( code.c_str() );

On only some, not all, of the nodes, when delete curr->data is reached, the destructor of the object it’s pointing to is called, then the parent’s destructor, and finally the base class destructor (all of them are empty). Sometimes it’s in the parent destructor, sometimes the base class destructor that the heap corruption message is shown.

Any suggestions on what the problem might stem from?

  • 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-27T09:11:55+00:00Added an answer on May 27, 2026 at 9:11 am

    This:

    delete curr->data;
    delete curr;
    
    curr->data = NULL;
    curr = NULL;
    

    is wrong. You shouldn’t write to curr->data after you deleted curr. Not even NULL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
Problem: Ajax suggest-search on [ n ] ingredients in recipes. That is: match recipes
Problem: We have a web app that calls some web services asynchronously (from the
Problem: I'm working on a website where there is a dial that displays a
Problem statement: I want to upload a large binary (such as an audio clip)
Problem: I have 2 classes, DB class and a User class, that will work
Problem: I have a large Visual C++ project that I'm trying to migrate to
PROBLEM : I am having problems getting socket.IO to connect in some circumstances, so
Problem: I need somehow to checkout an existing branch of a project that is

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.