title: does C automatically free allocated memory inside a function?
body: <p>I created the following function to get Date Time string:</p>
  
  <pre><code>char *GetDateTime (int Format)
  {
      if (Format &gt; 2) Format = 0;
  
      double  DateTimeNow;
      int     BufferLen;
      char    *DateTimeFormat [3] =   {   "%X %x" ,   //Time Date
                                          "%x"    ,   //Date
                                          "%X"    };  //Time
      char    *DateTimeBuffer = NULL;
  
                          GetCurrentDateTime      (&amp;DateTimeNow);
      BufferLen       =   FormatDateTimeString    (DateTimeNow, DateTimeFormat [Format], NULL, 0);
      DateTimeBuffer  =   malloc                  (BufferLen + 1);
      FormatDateTimeString    (DateTimeNow, DateTimeFormat [Format], DateTimeBuffer, BufferLen + 1 );
  
      return DateTimeBuffer;
  }
  </code></pre>
  
  <p>I do not free 'DateTimeBuffer' because I need to pass out its content.  I wonder if that memory clears itself.  Please help.</p>