Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #5343

Interpeting valgrind

From Ruben Safir <ruben@mrbrklyn.com>
Newsgroups comp.lang.c++
Subject Interpeting valgrind
Date 2011-05-22 23:03 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <irc4ok$dno$3@reader1.panix.com> (permalink)

Show all headers | View raw


I'm looking at valg5rind output.  Very interesting but I'm wondering 
about its output

I see for example


==2109== 
==2109== HEAP SUMMARY:
==2109==     in use at exit: 249,696 bytes in 32,929 blocks
==2109==   total heap usage: 39,794 allocs, 6,865 frees, 329,680 bytes allocated
==2109== 
==2109== 4 bytes in 1 blocks are still reachable in loss record 1 of 17
==2109==    at 0x4027400: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2109==    by 0x804B50D: chainlist::Node<chainlist::List<stats::Distribution<int> >*>::value(chainlist::List<stats::Distribution<int> >*) (linklist.h:112)
==2109==    by 0x804AC67: chainlist::Node<chainlist::List<stats::Distribution<int> >*>::Node(chainlist::List<stats::Distribution<int> >*, chainlist::Node<chainlist::List<stats::Distribution<int> >*>*) (linklist.h:82)
==2109==    by 0x8049938: chainlist::List<chainlist::List<stats::Distribution<int> >*>::insert(chainlist::List<stats::Distribution<int> >*) (linklist.h:267)
==2109==    by 0x8048D23: main (test_del2.cpp:84)
==2109== 



Looking at  linklist.h:112, 82, 267

these are part of my class

80
   template<class unk>
      Node<unk>::Node(unk val, Node<unk> *item_to_link_to){
	 value(val);
	 if(!item_to_link_to){
	    next_ = 0;
	 }

112

   template<class unk>
      void Node<unk>::value(unk val){
	 value_ = new unk(val);
      }

267

 template < class T >
      void List<T>::insert ( T val )
      {
	 if(!front()){
	    std::cout << "val is  here" << std::endl; 
	    Node<T> * tmp = new Node<T>(val);
	    std::cout << "tmp is " << tmp << std::endl; 
	    front(tmp);
	    endd(tmp);
	    cursor(tmp);
	    sizeup();
	    return;


Now, as far as I know, i took care of all these leaks in the destructuror
 template<class T>
      List<T>::~List<T>(){
	 remove_all();
//	 std::cout << "Deleted All*************"  << __LINE__ << std::endl;
      }

     void List<T>::remove_all(){

//	 std::cout << "remove_all " << __LINE__ << std::endl;
	 cursor() = front();
	 while(cursor() != endd()){
//	    std::cout << "remove_all the front line" << __LINE__ << std::endl;
	    remove_front();
	 }
//	 std::cout << "\n\nReached the End\n\n";
	 remove_front();
//	 std::cout << "\n\nDeleted Last Node\n\n";
      }

   template<class T>
      void List<T>::remove_front(){
////	 std::cout << "Removing the Front " << front() << " End of List is "<< endd() << std::endl;

	 if(front() == 0){
//	    std::cout << "Front  is NULL " << front() << std::endl;
	    return;
	 }
	 if(front() == endd()){
//
//	    std::cout << "Front  is End " << front() << std::endl;
	    Node<T> * tmp = front();
	    delete tmp;
	    front(0);
	    endd(0);
	    cursor() = 0;
	    sizedown();
	    return;
	 }

   template<class unk>
      Node<unk>::~Node(){
	 if(value_)
	    delete value_;
//	 std::cout << "Delete Node" << __LINE__ <<  std::endl;

      }



Anything not being destroyed is in global scope and left destroyed internationally...or so i thought

When the program ends, main stops and a whole cascade of deletes happen.  I've seen that happen in this code
and even had double deletes at one point.

Am I not seeing something?

Ruben

Back to comp.lang.c++ | Previous | NextNext in thread | Find similar


Thread

Interpeting valgrind Ruben Safir <ruben@mrbrklyn.com> - 2011-05-22 23:03 +0000
  Re: Interpeting valgrind Sam <sam@email-scan.com> - 2011-05-22 18:36 -0500
    Re: Interpeting valgrind mrbrklyn <ceo.brooklyn@gmail.com> - 2011-05-22 17:23 -0700
      Re: Interpeting valgrind Sam <sam@email-scan.com> - 2011-05-22 20:23 -0500
        Re: Interpeting valgrind Ruben Safir <ruben@mrbrklyn.com> - 2011-05-23 21:41 +0000
          Re: Interpeting valgrind Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-05-24 00:54 +0200
            Re: Interpeting valgrind Ruben Safir <ruben@mrbrklyn.com> - 2011-05-24 02:37 +0000
              Re: Interpeting valgrind Michael Doubez <michael.doubez@free.fr> - 2011-05-24 01:36 -0700
                Re: Interpeting valgrind Ruben Safir <mrbrklyn@panix.com> - 2011-05-27 18:08 +0000
                Re: Interpeting valgrind Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-05-27 22:43 +0000
                Re: Interpeting valgrind Ruben Safir <ruben@mrbrklyn.com> - 2011-05-27 23:01 +0000
                Re: Interpeting valgrind Michael Doubez <michael.doubez@free.fr> - 2011-05-29 12:41 -0700
            Re: Interpeting valgrind Ruben Safir <ruben@mrbrklyn.com> - 2011-05-24 02:48 +0000

csiph-web