title: Free memory for array of structs
body: <p>I have an array of structs which is previously allocated by malloc.
  To free it:
  free(temp) is ok? temp is the array's name.
  or I should free element by element?</p>
  
  <p>Yes.This the function.Well I added declarations of the structs.cur_node is a var of Node.I used Node to create linked list. And freed it node by node.</p>
  
  <pre><code>struct Node 
  {
  char   template_id[6];
  double tm_score;
  double rmsd;
  double sequence_id;
  int    length;
  double translation_vector1;
  double translation_vector2;
  double translation_vector3;
  double rotation_matrix1;
  double rotation_matrix2;
  double rotation_matrix3;
  double rotation_matrix4;
  double rotation_matrix5;
  double rotation_matrix6;
  double rotation_matrix7;
  double rotation_matrix8;
  double rotation_matrix9;
  char   target_sequence[2000];
  char   template_sequence[2000];
  struct Node  *next;
  };
  struct Node *start_node, *cur_node;
  typedef struct 
  {
  char   *template_id;
  double tm_score;
  double rmsd;
  double sequence_id;
  int    length;
  double translation_vector1;
  double translation_vector2;
  double translation_vector3;
  double rotation_matrix1;
  double rotation_matrix2;
  double rotation_matrix3;
  double rotation_matrix4;
  double rotation_matrix5;
  double rotation_matrix6;
  double rotation_matrix7;
  double rotation_matrix8;
  double rotation_matrix9;
  char   *target_sequence;
  char   *template_sequence;  
  } Node1;
  
  void traverseAlignLList()
  {
    Node1 *temp;  
    struct Node *old_node;
    int temp_counter=0; 
    cur_node=start_node;
    temp=malloc(alignCounter*sizeof(Node1));
    while(cur_node!=NULL)
    {
    temp[temp_counter].template_id=malloc(6*sizeof(char));
    strcpy(temp[temp_counter].template_id,cur_node-&gt;template_id);
  
    temp[temp_counter].tm_score=cur_node-&gt;tm_score;
    temp[temp_counter].rmsd=cur_node-&gt;rmsd;
    temp[temp_counter].sequence_id=cur_node-&gt;sequence_id;
    temp[temp_counter].length=cur_node-&gt;length;
    temp[temp_counter].translation_vector1=cur_node-&gt;translation_vector1;
    temp[temp_counter].translation_vector2=cur_node-&gt;translation_vector2;
    temp[temp_counter].translation_vector3=cur_node-&gt;translation_vector3;
    temp[temp_counter].rotation_matrix1=cur_node-&gt;rotation_matrix1;
    temp[temp_counter].rotation_matrix2=cur_node-&gt;rotation_matrix2;
    temp[temp_counter].rotation_matrix3=cur_node-&gt;rotation_matrix3;
    temp[temp_counter].rotation_matrix4=cur_node-&gt;rotation_matrix4;
    temp[temp_counter].rotation_matrix5=cur_node-&gt;rotation_matrix5;
    temp[temp_counter].rotation_matrix6=cur_node-&gt;rotation_matrix6;
    temp[temp_counter].rotation_matrix7=cur_node-&gt;rotation_matrix7;
    temp[temp_counter].rotation_matrix8=cur_node-&gt;rotation_matrix8;
    temp[temp_counter].rotation_matrix9=cur_node-&gt;rotation_matrix9;
    temp[temp_counter].target_sequence=malloc(2000*sizeof(char));
    strcpy(temp[temp_counter].target_sequence,cur_node-&gt;target_sequence);
    temp[temp_counter].template_sequence=malloc(2000*sizeof(char));
    strcpy(temp[temp_counter].template_sequence,cur_node-&gt;template_sequence);
    temp_counter++;
  
    old_node=cur_node;
    cur_node=cur_node-&gt;next;
    free(old_node);
    }
    addAlignData(temp);
    free(temp);
    //free(cur_node);
    //free(start_node);
    start_node=NULL;
    }
  </code></pre>