title: Function to free a struct in C
body: <p>I'm having a problem where when I call a function I wrote to free a struct my program terminates on the first free instruction.</p>
  
  <p>Here's the function:</p>
  
  <pre><code>void deleteJobNode(struct jobNode *node) {
      free(node-&gt;burstTime);
      free(node-&gt;jobIndex);
      free(node-&gt;next);
      free(node-&gt;priority);
      free(node-&gt;remainingTime);
      free(node);
  }
  </code></pre>
  
  <p>Here is the definition of the struct and the function used to allocate memory to the struct.</p>
  
  <pre><code>struct jobNode {
      struct jobNode *next;
      int jobIndex;
      int burstTime;
      int remainingTime;
      int priority;
  };
  
  struct jobNode *createJobNode(int newJobIndex, int newBurstTime, int newRemainingTime, int newPriority) {
      struct jobNode *newNode = (struct jobNode *)malloc(sizeof(struct jobNode));
      newNode-&gt;jobIndex = newJobIndex;
      newNode-&gt;burstTime = newBurstTime;
      newNode-&gt;remainingTime = newRemainingTime;
      newNode-&gt;priority = newPriority;
  
      if(newNode == NULL)
          printf("Node Creation Error");
  
      return newNode;
  }
  </code></pre>
  
  <p>I've edited the free function as suggested: </p>
  
  <pre><code>void deleteJobNode(struct jobNode *node) {
      free(node);
  }
  </code></pre>
  
  <p>However I get this error at runtime:</p>
  
  <pre><code>*** Error in `/home/jack7521/workspace/req1b/Debug/req1b': double free or corruption (fasttop): 0x00000000010c2090 ***
  </code></pre>