title: Getting a memory leak from dynamically allocated arrays
body: <p>I am trying to write a program that reverses a users input string. if they enter "book" it should return "koob". I have to call the function reverseit(char *inputString, char *outputString) and write my algorithm in that.</p>
  
  <p>I have everything working but it returns a malloc error at the end </p>
  
  <pre><code>:malloc: *** error for object 0x7fff5c8a5bc0: pointer being freed was not allocated
  *** set a breakpoint in malloc_error_break to debug
  Abort trap: 6
  </code></pre>
  
  <p>The code i wrote:</p>
  
  <pre><code>void reverseit(char *inputString, char* outputString);
  
  int main()
  {
      char input[100];
      cin.getline(input, 10);
      int lenn = strlen(input); 
      char* usrinput = new char[lenn+1];
      usrinput = input;
      int len = strlen(usrinput);
      char* inputString = new char[len+1];
      inputString = usrinput;
      char* outputString = new char[len+1];
      reverseit(inputString, outputString);
      for (int o = 0; o &lt; len; o++)
      {
          cout &lt;&lt; outputString[o];
      }
      cout &lt;&lt; endl;
      delete [] usrinput;
      delete [] inputString;
      delete [] outputString;
      return 0;
  
  }
  
  void reverseit(char *inputString, char *outputString)
  {
      size_t length = strlen(inputString);
      char temp;
      int k = 0;
      for(int i = length - 1; i &gt;= 0 ; i--)
      {
          temp = inputString[i];
          outputString[k] = temp;
          k++;
      }
  }
  </code></pre>
  
  <p>There are several restrictions that are really making this more difficult than it actually is, because I am not allowed to call any other variables into reverseit except the two char pointers. </p>
  
  <p>My specific question is if I am deleting all my dynamic arrays how are the memory leaks still happening, could the leak be happening because I am not entering the correct size for each array? Thank you</p>