title: Free array of pointers
body: <p>I have this test code : </p>
  
  <pre><code>void test2(){
  
      char** twoDArray = (char**)calloc(3,sizeof(char*));
      char* element1 = (char*)calloc(3,sizeof(char));
  
      twoDArray[0] = element1;    
      twoDArray[1] = element1;
      twoDArray[2] = element1;
  
      freeArray(twoDArray,3);
  
  }
  
  void freeArray(char** arr,int size){
      if(arr!= NULL){
          for(int i =0 ;i &lt; size;i++){
              if(arr[i] != NULL){
                  free(arr[i]);
                  arr[i] = NULL;
              }
          }
          free(arr);
          arr = NULL;
      }
  }
  </code></pre>
  
  <p>in second iteration of loop in <code>freeArray</code> <code>arr[1] != NULL</code> give 'true' and error occurs, why ? How to properly free such array ?</p>