title: how to free dynamic memory allocated inside function after finishing execution
body: <p>how to free dynamic memory allocated inside function
  after finishing execution</p>
  
  <p>i allocated two char *  str2R &amp; str4R
  and my function is</p>
  
  <pre><code>char * MMP(char * index)
  {
  
      char* str1= "AT+CMGR=";
      char* str2R = (char *) malloc(1 + strlen(str1)+ strlen(index) );
      strcpy(str2R, str1);
      strcat(str2R, index);
  
      char* str3="\r";
      char* str4R = (char *) malloc(1 + strlen(str2R)+ strlen(str3) );
      strcpy(str4R, str2R);
      strcat(str4R, str3);
  
  
      return str4R;
  
  };
  </code></pre>
  
  <p>when i call</p>
  
  <pre><code>  free(str2R);
    free(str4R);
  </code></pre>
  
  <p>in main or in another file after calling the function
  this error appears </p>
  
  <p>error: str2R undeclared (first use in this function)</p>
  
  <p>thanks in advance</p>