title: How to free an array of char-pointer?
body: <p>I use this Method to convert values from a list into an array for use in an execvp()-Systemcall:</p>
  
  <pre><code>char **list2argarray(struct shellvalue *values, int count)
  {
      char **array = (char **)malloc((count + 1) * sizeof(char *));
      int i = 0;
  
      while (values)
      {
          char *word = values-&gt;word;
  
          array[i] = (char *)malloc(sizeof(word) + 1);
          strcpy(array[i], word);
          values = values-&gt;next;
          i++;
      }
      array[i] = NULL;
      return array;
  }
  </code></pre>
  
  <p>What is a proper way to free such Arrays? I tried it with things like </p>
  
  <pre><code>void freeargpointer(char **array, int count)
  {
      int i = 0;
  
      while (*array)
      {
          free(*array);
          (*array)++;
      }
  }
  </code></pre>
  
  <p>But everytime when i reach the free-syscall, while debugging, the programm crashes with errors like this one:</p>
  
  <blockquote>
    <p>free(): invalid next size (fast): 0x000000000060c180 ****</p>
  </blockquote>