title: C++ linked list memory leak
body: <p>Hi I ran my program through valgrind and this is the report</p>
  
  <p>Heap Summary:
  in use at exit: 8 bytes in 1 blocks
  total heap usag: 1 allocs, 0 frees, 8 bytes allocated
  Leak Summary:
  definitely lost: 8 bytes in 1 blocks</p>
  
  <p>This is my program</p>
  
  <pre><code>int main() {    
  NodeData nodedata1(1, 'a');
  List list1;
  list1.insert(&amp;nodedata1);
  
     return 0;
  }
  //---my List class
  class List {
  public:
     List(); 
     bool insert(NodeData*);                     // insert one Node into list
     bool isEmpty() const; 
  private:
     struct Node {              // the node in a linked list
        NodeData* data;         // pointer to actual data, operations in NodeData
        Node* next;
     };
     Node* head;                                 // pointer to first node in list
  };
  // my bool insert method
  bool List::insert(NodeData* rightPtr) {  
     Node* newPtr = new Node;
     newPtr-&gt;data = rightPtr;    
     if (isEmpty() || *newPtr-&gt;data &lt; *head-&gt;data) {
        newPtr-&gt;next = head;                           
        head = newPtr;
     }
     else {
        Node* current = head; 
        while (current-&gt;next !=NULL &amp;&amp; *current-&gt;next-&gt;data &lt; *newPtr-&gt;data) {
             current = current-&gt;next;
        }
        newPtr-&gt;next = current-&gt;next;
        current-&gt;next = newPtr;
     }
     return true;
  }
  </code></pre>