title: Char* Array Memory Leak
body: <p>I am having issues de-allocating memory that I used in my <code>char*</code> array. In my code snippet below, I am creating a <code>char*</code> array named <code>input</code> that holds pointers to single words at a time followed by a pointer<code>NULL</code> at the end of the array. This is the only time (I believe) I allocate memory in my code.</p>
  
  <pre><code>char* input[999];
  //exec commands 
  for(unsigned int i = 0; i &lt; commands.size(); i++)
  {
      string current = "";
      string word = "";
      int k = 0;
      for(unsigned int j = 0; j &lt; commands.at(i).size(); j++) //iterate through letters
      {
          current = commands.at(i);
          //cout &lt;&lt; "current: " &lt;&lt; current &lt;&lt; endl;
          if(current[j] == ' ')
          {
              input[k] = new char[word.size() + 1];
              strcpy(input[k], word.c_str());
              k++;
              word = "";
          }
          else
              word += current[j]; //add letter
          //cout &lt;&lt; "word: " &lt;&lt; word &lt;&lt; endl;
      }
      input[k] = new char[word.size() + 1];
      strcpy(input[k], word.c_str());
      k++;
      input[k] = new char[1]; //add the NULL char *
      input[k] = NULL;
      ...
  </code></pre>
  
  <p>Later on, I attempt to de-allocate this memory with this snippet of code:</p>
  
  <pre><code>for(int z = 0; z &lt; k; z++)
  {
      delete[] input[z];
  }
  </code></pre>
  
  <p>I am iterating through my <code>char*</code> array and deleting the memory allocated at each index. Without using this snippet, valgrind informs me of memory leaks. Using this snippet, valgrind informs me of less memory leaks than before.  I am still stuck with the issue of memory still being <em>definitely lost</em>. </p>
  
  <p>I am unsure what I am missing to remove the rest of the allocated memory (or if the cause of the rest of the memory leaks is in fact somewhere else in my code). I appreciate any and all help, suggestions, and tips.</p>