title: Allocating space for a reference returned
body: <p>I have created a function to calculate the difference of 2 timeval functions. Here is the basic version of that function.</p>
  
  <pre><code>struct timeval* getDifference(struct timeval* startTime, struct timeval* finishTime)
  {
      struct timeval* difference = new struct timeval;
      difference-&gt;tv_sec = finishTime-&gt;tv_sec - startTime-&gt;tv_sec;
      difference-&gt;tv_usec = finishTime-&gt;tv_usec - startTime-&gt;tv_usec;
      return difference;
  }
  
  int main()
  {
      struct timeval a,b;
      struct timeval* c;
      gettimeofday(&amp;a, NULL);
      usleep(100000);
      gettimeofday(&amp;b, NULL);
  
      c = getDifference(&amp;a, &amp;b);
   }
  </code></pre>
  
  <p>What i want to know is if the usage <code>struct timeval* c;</code> safe? or should it be like <code>struct timeval* c = new struct timeval;</code>?</p>
  
  <p>If it is safe then would freeing <code>c</code> free the <code>difference = new struct timeval;</code> allocated inside the function?</p>