title: free() not freeing string from array of structs
body: <p>Hi so I am creating a program that uses a hash to store words and their number of occurrences from a text file. That works as intended. The issue I am having comes from freeing the allocated memory. </p>
  
  <p>Here is my hash</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  #include&lt;ctype.h&gt;
  #include"hash.h"
  
  /*
  struct listnode{
      char * word;
      int count;
  };
  */
  
  void hashCreate(struct listnode * hashTable[], int size){
      int i;
      for(i=0;i&lt;size;i++){
          hashTable[i]=(struct listnode *)malloc(sizeof(struct listnode));
          hashTable[i]-&gt;count=0;
      }
  }
  
  int hash(char * data, int size) {
    unsigned long hash = 5381;
    char * p;
    for (p = data; *p != '\0'; ++p) {
      hash = (hash * 33) + *p;
    }
    return (int)(hash % size);
  }
  
  void hashAdd(char * data, struct listnode * hashTable[], int size){
      int key=hash(data, size);
      hashTable[key]-&gt;word=strdup(data);
      hashTable[key]-&gt;count+=1;
  }
  
  void hashPrint(struct listnode * hashTable[], int size){
      int i;
      for(i=0;i&lt;size;i++){
          if(hashTable[i]-&gt;count!=0)
          printf("%s: %d \n",hashTable[i]-&gt;word,hashTable[i]-&gt;count);
      }
  }
  
  void hashDelete(struct listnode * hashTable[],int size){
      int i;
      for(i=0;i&lt;size;i++){
          free(hashTable[i]-&gt;word);
          free(hashTable[i]);
      }
  }
  </code></pre>
  
  <p>This is what uses it</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  #include&lt;ctype.h&gt;
  #include"hash.h"
  
  /*
  int hash(char * data, int size) {
    unsigned long hash = 5381;
    char * p;
    for (p = data; *p != '\0'; ++p) {
      hash = (hash * 33) + *p;
    }
    return (int)(hash % size);
  }
  */
  
  #define SIZE 1500
  
  
  void removePunct(char * str);
  void fileRead(char * filename);
  
  
  struct listnode * hashTable[1500];
  
  int main(int argc, char ** argv){
      int i;
      if(argc&lt;2)
          fprintf(stderr,"Enter filename \n");
  
      hashCreate(hashTable, SIZE);
  
      for(i=1; i&lt;argc; i++){
          fileRead(argv[i]);
      }
  
      hashPrint(hashTable,SIZE);
      hashDelete(hashTable, SIZE);
      return 0;
  }
  
  void fileRead(char * filename){
      FILE * file = fopen(filename,"r");
      char word[80];
      if(!file){
          fprintf(stderr,"Error opening file \n");
          return;
          }
      while(fscanf(file, "%s", word)==1){
          removePunct(word);
          hashAdd(word,hashTable,SIZE);
      }
      fclose(file);
  }
  
  void removePunct(char * str){
      int i,p=0;
      for(i=0; i&lt;strlen(str);i++){
          if(isalpha(str[i]) || str[i]==' '){
              str[p]=tolower(str[i]);
              p++;
          }
      }
      str[p]='\0';
  }
  </code></pre>
  
  <p>In my hashDelete function the strings are not being freed which is causing a memory leak. I tested it by freeing the string within the hashAdd function and there were no memory leaks but there were also no strings being printed. Im unable to find the issue that is not letting me free all my memory. Any help would be appreciated.</p>