title: Using malloc like this is correct?
body: <p>I am new to dynamic memory allocation.
  Does this type of use create any memory leak or unallocated memory access?</p>
  
  <pre><code>char *func2(char *str) {
      //Do something like writing 10 characters to str
      return str;
  }
  
  void func1() {
      char *str = NULL, *res;
      int len = 10;
      str = (char *)malloc(len * sizeof(char));
      res = func2(str);
      free(str); 
      printf("%s", res);
  }
  </code></pre>
  
  <p>Does the final printf statement in <code>func1</code> result in segmentation fault as <code>str</code> is already freed, will <code>res</code> be a dangling pointer, with no memory location to point?</p>