title: returning local variables
body: <p>I came across an issue today regarding local variables.  I learned that...</p>
  
  <pre><code> int * somefunc()
   {
       int x = 5;
       return &amp;x;
   }
  
   int * y = somefunc();
   //do something
  </code></pre>
  
  <p>is bad, unsafe, etc.  I'd imagine that the case is the same for...</p>
  
  <pre><code>int * somefunc()
  {
      int * x = new int;
      x = 5;
      return x;
  }
  
  int * y = somefunc();
  //do something
  delete y;
  </code></pre>
  
  <p>I've been under the impression for the longest time that this would be safe as the address of x stays in scope when it's returned.  However, I'm having second thoughts now and I'm thinking this would lead to memory leaks and other problems, just as the fist example would.  Can someone confirm this for me?</p>