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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:02:40+00:00 2026-06-09T08:02:40+00:00

I ran purify on my code which runs in Solaris and it shows lot

  • 0

I ran purify on my code which runs in Solaris and it shows lot of memory leaks.
But I checked the code and most of the leaks seem to be invalid.

For eg,

File1.cpp

Obj* getMyObj()
{
    Obj* obj = NULL;
    if(condition)
    {
        obj = new Obj();   //Purify is reporting leak here
        //Fill obj
    }

    ...
    return obj;
}

File2.cpp

void myfunc()
{
    Obj* myobj = getMyObj();

   if(myobj == NULL)
       return;
    ...
    ...

    delete myobj;    //The object is deleted here
}

Even though the object is destroyed properly in File2.cpp, why is purify reporting leak in File1.cpp?

EDIT

The NULL check was just a typo, I corrected it.

  • 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-06-09T08:02:42+00:00Added an answer on June 9, 2026 at 8:02 am

    Even though the object is destroyed properly in File2.cpp, […]

    This assumption is wrong.

    Obj* myobj = getMyObj();
    

    If getMyObj actually creates an object, it won’t return a null pointer. That means the condition in the following if is true, and then the function returns immediately.

    if(myobj)
        return;
    

    No further code executes in that function, so it’s never destroyed.

    I recommend the use of smart pointers instead of this kind of manual management, as this kind of errors just goes away. With C++11 you can use std::unique_ptr, otherwise you can use std::auto_ptr if you’re careful.

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

Sidebar

Related Questions

I ran into an issue. Below is my code, which asks user for input
Ran into a bit of an issue with some jQuery code, but in essence,
Ran the new Lint tool against my code. It came up with a lot
I ran into a scenario where I had a delegate callback which could occur
Ran across this, but I cannot quite grasp it, especially beginning with the LIMIT
I ran port scan and it shows port 25 closed. I turn off the
I ran JSLint on some inherited code, and received the following: Problem at line
I ran the following code, and it stated is executed correctly. It is the
Ran accross the following code in an article and didn't think it was standard
I ran into this code on Wikipedia : (define (pyth x y k) (*

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.