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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:23:25+00:00 2026-06-08T03:23:25+00:00

I’m trying to figure out Valgrind usage so I made a simple program but

  • 0

I’m trying to figure out Valgrind usage so I made a simple program but it seems Valgrind gives a strange error when I do dynamic mem allocation in class.

My program is:

class Valgrind_testclass
{
 Valgrind_testclass *Obj;
public:
  Valgrind_testclass() { 
    // Obj = new Valgrind_testclass();  // Test point #3
  }
  ~Valgrind_testclass() {
    //delete Obj;               // Test point #4
  }
};

int main()
{
 Valgrind_testclass valObj;
 // Valgrind_testclass * valObjPtr = new Valgrind_testclass();  // Test point #1
 //delete valObjPtr;                 // Test point #2
 return 0;
}

With commented out test points Valgrind gives me the following:

==5273== HEAP SUMMARY:
==5273==     in use at exit: 0 bytes in 0 blocks
==5273==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated

which I suppose is the expected result.

Now when I uncomment test point #1:

==5288== HEAP SUMMARY:
==5288==     in use at exit: 4 bytes in 1 blocks
==5288==   total heap usage: 1 allocs, 0 frees, 4 bytes allocated
==5288== 
==5288== Searching for pointers to 1 not-freed blocks
==5288== Checked 102,116 bytes
==5288== 
==5288== 4 bytes in 1 blocks are definitely lost in loss record 1 of 1

which again is the correct result since I’m not performing the deletion.

With test point #2 uncommented I get:

==5300== HEAP SUMMARY:
==5300==     in use at exit: 0 bytes in 0 blocks
==5300==   total heap usage: 1 allocs, 1 frees, 4 bytes allocated
==5300== 
==5300== All heap blocks were freed -- no leaks are possible

Again correct result.

Now I uncomment test point #3, and I expect Valgrind to detect the memory leak. This is what I get:

==5313== Process terminating with default action of signal 11 (SIGSEGV)
==5313==  Access not within mapped region at address 0xBE17AFE4
==5313==    at 0x40263A0: operator new(unsigned int) (vg_replace_malloc.c:255)
==5313==  If you believe this happened as a result of a stack
==5313==  overflow in your program's main thread (unlikely but
==5313==  possible), you can try to increase the size of the
==5313==  main thread stack using the --main-stacksize= flag.
==5313==  The main thread stack size used in this run was 8388608.
==5313== Stack overflow in thread 1: can't grow stack to 0xbe17afe0
==5313== 
==5313== Process terminating with default action of signal 11 (SIGSEGV)
==5313==  Access not within mapped region at address 0xBE17AFE0
==5313==    at 0x402040C: _vgnU_freeres (vg_preloaded.c:58)
==5313==  If you believe this happened as a result of a stack
==5313==  overflow in your program's main thread (unlikely but
==5313==  possible), you can try to increase the size of the
==5313==  main thread stack using the --main-stacksize= flag.
==5313==  The main thread stack size used in this run was 8388608.
==5313== 
==5313== HEAP SUMMARY:
==5313==     in use at exit: 1,047,576 bytes in 261,894 blocks
==5313==   total heap usage: 261,894 allocs, 0 frees, 1,047,576 bytes allocated
==5313== 
==5313== Searching for pointers to 261,894 not-freed blocks
==5313== Checked 5,339,952 bytes
==5313== 
==5313== LEAK SUMMARY:
==5313==    definitely lost: 0 bytes in 0 blocks
==5313==    indirectly lost: 0 bytes in 0 blocks
==5313==      possibly lost: 0 bytes in 0 blocks
==5313==    still reachable: 1,047,576 bytes in 261,894 blocks
==5313==         suppressed: 0 bytes in 0 blocks
==5313== Reachable blocks (those to which a pointer was found) are not shown.
==5313== To see them, rerun with: --leak-check=full --show-reachable=yes
==5313== 
==5313== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from 6)

I’m not sure why I’m not seeing a similar memory leak error here.
Could somebody please help in understanding this situation, whether I’m doing something wrong.
The Valgrind command I use is:

valgrind -v --tool=memcheck --leak-check=full --num-callers=40  ./ValgrindOutput 

Thank you.

  • 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-08T03:23:28+00:00Added an answer on June 8, 2026 at 3:23 am

    This is because you have infinite recursion

    Valgrind_testclass is new’ing a Valgrind_testclass which is new’ing another Valgrind_testclass …ad infinitum

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:

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.