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 6387097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:06:34+00:00 2026-05-25T03:06:34+00:00

I have a class Foo, which has a (simple) destructor. Some other class contains

  • 0

I have a class Foo, which has a (simple) destructor.

Some other class contains an array of Foo objects (called foolist), in the destructor of that class, I do:

delete[] foolist;

This crashes (gdb shows that it crashes in this exact line). However, by using printouts I see that all the elements in foolist are finishing their destructor without problems (the number of destructors that runned is also equal to the number of objects allocated in this array, so they all get destructed). There is also no other delete for foolist in the code.

I also made sure that foolist is indeed initialized as an array, in this way:

foolist = new Foo[number];

The error is:

*** glibc detected *** /home/bas/projects/trunk/main:
free(): invalid next size (fast): 0x080a0e80 ***

What could cause delete[] to crash in this case?

Thanks in advance!

As asked also the output of valgind here (statementNode is Foo, and programNode the class containing list of Foo’s)

==4111== 1 errors in context 1 of 2:
==4111== Invalid write of size 4
==4111==    at 0x804B6FA: Parser::parseProgram(std::string) (statementnode.h:35)
==4111==    by 0x80764D4: main (parser.h:35)
==4111==  Address 0x42d9bdc is 4 bytes after a block of size 32 alloc'd
==4111==    at 0x4025F53: operator new[](unsigned int) (vg_replace_malloc.c:299)
==4111==    by 0x804A81E: Parser::parseProgram(std::string) (programnode.h:21)
==4111==    by 0x80764D4: main (parser.h:35)

StatementNode:35 is the creation of a completly different object. ProgramNode:21 is the creation of foolist / list of StatementNodes.. Hope this helps.

  • 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-25T03:06:35+00:00Added an answer on May 25, 2026 at 3:06 am

    The delete operator performs 2 functions under the hood

    1. Run Destructors
    2. Free Memory

    Given the printout confirms #1 is happening the most likely cause is a crash during the actual freeing of memory (the message indicates this as well). This typically indicates that the memory is being corrupted by another part of your program.

    Have you tried running your program under valgrind?

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

Sidebar

Related Questions

I have a base class Foo that has an Update() function, which I want
I have a simple class which has boolean field: public struct Foo { bool
My situation is essentially this: I have a class called Foo which has dependencies
Let's say we have a class foo which has a private instance variable bar
Imagine I have a C++ class Foo and a class Bar which has to
I have a class Foo which has_many Bars. Foo has an attribute, some_id. I
I have an ASP.NET GridView which has columns that look like this: | Foo
I have a class which has a group of integers, say foo() { int
I have a really simple coffescript class: class Bar foo: -> console.log('bar') Which when
I have a class which is not thread safe: class Foo { /* Abstract

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.