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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:26:54+00:00 2026-05-13T06:26:54+00:00

Reviewing a quite old project I found the following curious code snippet (only relevant

  • 0

Reviewing a quite old project I found the following curious code snippet (only relevant code extracted):

class CCuriousClass {
    ~CCuriousClass();
    CSomeType* object;
};

CCuriousClass::~CCuriousClass()
{
    while( object != NULL ) {
        delete object;
    }
}

Have I overseen anything or is it a plain road to undefined behaviour?

What I see here is that if object is a null pointer at the point of CCuriousClass::~CCuriousClass() being called everything will be fine – no action taken – but if object is not null this will be an infinite loop with undefined behaviour inside.

Is this most likely a bug or some smart construct I don’t understand?

  • 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-13T06:26:55+00:00Added an answer on May 13, 2026 at 6:26 am

    Since your question seems to imply “What could somebody have meant with this?” and not “Why is this a fantastic idea?” I suggest the following:

    class CSomeType {
        CCuriousClass* m_plistentry;
        CSomeType* m_pnext;
    
        ~CSomeType() {
            m_plistentry->object = m_pnext;
        }
    };
    

    The basic idea could have been that the owner points to the head of a list, and the list can only be deleted at the head. If the head gets deleted, it sets its parent pointer to the new head of the list. If the parent is destructed, it destroys every list element.

    Now this is clearly code from crazy town.

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

Sidebar

Related Questions

I'm reviewing a quite old project and see code like this for the second
I'm reviewing some code on the project I recently joined, and in a C#
When reviewing our codebase, I found an inheritance structure that resembles the following pattern:
I was reviewing some of my old code and I have a method that
I was reviewing code and found that $(#item1 #item2) and $(#item1>#item2) are used interchangeably.
I'm just reviewing some of my old code (have some spare time), and I
While reviewing Visual C++ codebase I found a following strange thing. A run-time assert
Whilst reviewing some Qt C++ code I came across this: class Foo { Q_OBJECT
I'm reviewing some code from one of our contractors: if (userLists != null) {
I was just reviewing one of my client's applications which uses some old outdated

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.