title: How to properly malloc item in struct array hashmap in C
body: <p>In the following code, I'm using malloc for adding a new item to a hashmap. I thought I've checked all the boxes for properly using malloc, but valgrind says I've got a memory leak on them. Can someone point me to where I've gone wrong?</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  typedef struct node
  {
      char content[46];
      struct node* next;
  }
  node;
  
  typedef node* hashmap_t;
  
  int main (int argc, char *argv[]) {
  
      hashmap_t hashtable[1000];
  
      node *n = malloc(sizeof(node));
      if(n == NULL) return 0;
  
      hashmap_t new_node = n;
  
      new_node-&gt;next = malloc(sizeof(node));
      if(new_node-&gt;next == NULL) {
          free(n);
          return 0;
      }
  
      strncpy(new_node-&gt;content, "hello", 45);
      hashtable[10] = new_node;
  
      for(int y=0; y &lt; 1000; y++) {
          if(hashtable[y] != NULL) {
              free(hashtable[y]-&gt;next);
              free(hashtable[y]);
          }
      }
  
      return 1;
  }
  </code></pre>