title: Resource leak during object creation
body: <p>I have the following code for creation of a node inside a graph. I'm getting resource leak error when I run a static checking tool (coverity). I would appreciate if you can point out how to improve the code: </p>
  
  <pre><code>class node {   
     public :  
       explicit node(std::string&amp; name) : m_name(name) { }  
       void setlevel(int level)  
       { m_level = level; }  
     private :    
       ...  
   }  
  class graph {  
     public :  
        void populateGraph()  
        {  
           std::string nodeName = getNodeName();   
           /* I get error saying variable from new not freed or pointed-to in function  
              nc::node::node(const std::string...) */  
           node* NodePtr = new node(nodeName);  
           /* I get error saying variable NodePtr not freed or pointed-to in function  
              nc::node::setLevel(int) */   
           NodePtr-&gt;setLevel(-1);  
           if (m_name2NodeMap.find(nodeName) == m_name2NodeMap.end())  
               m_name2NodeMap[nodeName] = NodePtr;  
           NodePtr = NULL;  
        }  
  ....  
  private :  
    std::map&lt; std::string, node*&gt; m_name2NodeMap;   
  }
  </code></pre>
  
  <p><br>
  I thought I needed to <code>delete NodePtr</code> in <code>populateGraph</code>, but then released it will call node desctructor (<code>~node</code>) and delete the node from the graph. So, I set <code>NodePtr=NULL</code> to see if it helps, but it is not.</p>