title: Does memory used of returned variables from functions need to be freed (C)?
body: <p>Let's suppose I have the following C code:</p>
  
  <pre><code>void myfunction() {
      time_t     t = 0;
      struct tm  *ct;
  
      time(&amp;t);
      ct = localtime(&amp;t);
  }
  </code></pre>
  
  <p>As you can see, the <code>localtime</code> function returns a new pointer to a <code>struct tm</code> variable. From what I know, for a returned variable from a function to be valid in the caller context it needs to fulfill at least one of the following:</p>
  
  <ol>
  <li>The returned variable must be declared in the caller's context or a higher context related to caller.</li>
  <li>The returned variable must have the allocated memory on the heap.</li>
  </ol>
  
  <p>In my case the first point does not apply, so it is normal to think that 2nd is fulfilled.</p>
  
  <p>Am I right?</p>
  
  <p>If yes, does that mean that I need to call free on <code>ct</code> variable after using it?</p>
  
  <p>If not, can you detail a little bit?</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>From the responses, I understood that there should be another point in the requirements that a variable to be usable in the context where returned. That should be the static variables. Is there another possibility?</p>