title: Freeing a double pointer from a struct
body: <p>I have a problem with my delete_table function. So i have 2 structs </p>
  
  <pre><code>struct _entry_ {
      int key;
      int data;
      struct _entry_* next;
      struct _entry_* prev;
  };
  typedef struct _entry_ entry;
  
  struct _table_ {
      entry** entries;
      int size;
  };
  typedef struct _table_ table;
  </code></pre>
  
  <p>I initialise my table with calloc.</p>
  
  <pre><code>void table_init(table* ht, int initial_size) {
      ht-&gt;entries = (entry**)calloc(initial_size, sizeof(entry*));
      if (ht-&gt;entries) {
          ht-&gt;size = initial_size;
      }
  }
  </code></pre>
  
  <p>Now my free function that i wrote </p>
  
  <pre><code>void table_destroy(htable* ht) {
  
      entry *el, *temp;
      int i;
      for(i = 0; i &lt; ht-&gt;size; i++) {
        el = ht-&gt;entries[i];
        while(el != NULL){
          temp = el;
          el = el-&gt;next;
          free(temp);
        }
        free(ht-&gt;entries[i]);
      }
      free(ht); // &lt;- don't know do i need this.
  }
  </code></pre>
  
  <p>When i test it with valgrind i got this error</p>
  
  <pre><code>==13560== Invalid free() / delete / delete[] / realloc()
  ==13560==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==13560==    by 0x400783: htable_destroy (htable.c:46)
  ==13560==    by 0x400A24: main (main.c:25)
  ==13560==  Address 0xffefffae0 is on thread 1's stack
  ==13560==  in frame #2, created by main (main.c:7)
  </code></pre>
  
  <p>Any help would be great, thank you for your time!</p>