title: How to free a tree structure in C with a double pointer
body: <p>I'm doing a code about the construction of a tree structure in C, which is not binary. The structure contains a horizontal, a vertical link and a char value. Now i'm trying to free every structure allocated to construct this tree but valgrind gives me an error. I am using a double pointer to point the head of the tree. In the function pile means stack so I stack every node vertically and then I search for the horizontal ones. I'm putting as a picture an example of a tree and its structure and the valgrind result. Can you please help me to understand what is wrong because I don't get it ? Thank you ! </p>
  
  <pre><code>void libererArbre(cellule ** tete)
  {
      cellule * cour = * tete;
      cellule ** temp = &amp;cour; 
      pile_t * pile;
      pile = initialisationPile(TAILLE_PILE);
      int fin = 0;    
      while(fin == 0)
      {   
          while(cour != NULL)
          {
              empiler(cour, pile);
              //printf("empilimi %c\n", cour-&gt;valeur);
              cour = cour-&gt;lienVertical;
          }
          if(!estVidePile(pile))
          {
              cour = depiler(pile);
              //printf("depilimi %c\n", cour-&gt;valeur);
              temp = &amp;cour;
              free(temp);
              cour = cour-&gt;lienHorizontal;    
          }
          else
          {
              fin = 1;
              printf("a futet ne fin 1 apo jo \n");
          }
      }
      libererPile(pile);
  }
  </code></pre>
  
  <p>Here's a picture of the result of valgrind: </p>
  
  <p><img src="https://i.stack.imgur.com/37wR3.png" alt="enter image description here"></p>
  
  <p>Here's a picture of the explination of the structure:</p>
  
  <p><img src="https://i.stack.imgur.com/QCw0z.png" alt="enter image description here"></p>