title: Free a pointer local to a function and return the pointer
body: <p>I have a C code similar to this. How can I free the pointer and return it ? If I create another local pointer variable and assign <code>p</code> to that local pointer variable, it is showing a warning that local variable pointer cannot be returned. <strong>Note that I have a recursion so I want to free up the pointer in the  function itself.</strong> Any workaround. Thanks in advance.  </p>
  
  <pre><code>char * ABCfunction(){
      char * p = malloc(10*sizeof(char));
      //do something with p
      ABCfunction();
      return p;
      //free(p); //Want to do both.
  }  
  </code></pre>
  
  <p><strong>UPDATE: Yes, I know that it makes no sense and we cannot do both. I am asking for an alternative approach. The problem is if I don't free the pointer, it is consuming a lot of memory for high input values. I want to get rid of high memory usage.</strong></p>