title: C++ app: How to properly delete/release an allocated object?
body: <p>I am using a GCC compiler on Ubuntu 14.04.<br>
  I have a small communication app (not written by me) and I intend to embed it into my own app.<br>
  The small comm. app code looks like this:    </p>
  
  <pre><code>UartComm * commInterface;   
  ...   
  void commInit()   
  {   
     commInterface = new UartComm;   
  }   
  
  // other functions here that use "commInterface"
  // ...
  
  int main()   
  {
     commInit();   
     ...   
     if(smthing_1)
        return (-1);  
     if(smthing_2)
        return (-2);  
     ...
     if(smthing_n)
        return (-n);  
     //
     return (0);
  }   
  </code></pre>
  
  <p>--<br>
  As seen above there is no <code>delete commInterface;</code> in the original code so, if I embed the above code into my app, rename <code>main()</code> to <code>commFunction()</code> and call it many times, I will have a lot of memory that is not de-allocated.<br>
  The above code is a simplified version. In fact, the code has many exit points/returns. It also has some functions that throw exceptions (I'm not 100% sure they're all catched and handled properly).<br>
  So, I guess adding <code>delete commInterface;</code> before all <code>returns</code> will not be enough in this case...<br>
  Hence, my question: Is there a way to properly delete/release <code>commInterface</code> in order to embed and use the above module without worrying about memory leaks? Smart pointer maybe or some other idea...?<br>
  <strong><em>Two remarks</em></strong>:<br>
  <strong>1)</strong> I've enabled C++11;<br>
  <strong>2)</strong> I' not using (and don't wanna use) <em>boost</em>.<br>
  Thanks in advance for your time and patience.</p>