title: 448 bytes in 28 blocks are definitely lost in loss record 1 of 1 - problems with FREED memory
body: <p>I have created an array of structs. Each element of the array is meant to allocate up to 4 digits; there can be less digits. Initially, the are set to 0. I have some memory leaks in program and I would like to ask about the first one:</p>
  <pre><code>#include &lt;stdlib.h&gt;
  
  #define ELEMENTS 8
  #define NUM_INT 4   //Number of digits
  
  typedef struct sth {
      int* numbers;
      int how_many;  //How many cells with 4 digits
  } sth;
  
  
  void create(sth** tab) {
      *tab = realloc(*tab, ELEMENTS * sizeof(**tab)); 
      for (int i = 0; i &lt; ELEMENTS; i++) {
          sth cell; 
          cell.numbers = calloc(NUM_INT, sizeof (*cell.numbers));
          cell.how_many = 1;
          (*tab)[i] = cell; // Put in original array.
       }
       (*tab)[ELEMENTS-2].numbers[0] = -1; // Don't bother about the values
       (*tab)[ELEMENTS-1].numbers[0] = 1;
  }
  
  void clear(sth** arr) {
      free(*arr);
      *arr = NULL;
  }
  
  int main(void) {
      sth* arr = NULL; // Don't need to initialise to null here.
      create(&amp;arr);
      //There have been functions, but I commented them out
      clear(&amp;arr);
      return 0;
  }
  </code></pre>
  <p>When I run the program, I get by Valgrind:</p>
  <pre><code>    ==58759== 448 bytes in 28 blocks are definitely lost in loss record 1 of 1                                       
      ==58759==    at 0x4837B65: calloc (vg_replace_malloc.c:752)                                                             
      ==58759==    by 0x1091D6: create (address_of_a_file)                       
      ==58759==    by 0x10A3F4: main (address_of_a_file)                                 
      ==58759== 
  </code></pre>
  <p>Earlier I have used realloc instead of calloc and vilgrind indicated line:</p>
  <pre><code>sth cell;
  sth cell.numbers = NULL;
  cell.numbers = realloc(cell.numbers, NUM_INTS*sizeof(*cell.numbers));  //this line
  </code></pre>
  <p>As I have written, in the whole program occur memory leaks, but I want to track the first source of them.</p>
  <p>For me it seems as if I have created new allocated memory and have not freed the previous content. However I don't know, what is the cause of the problem here, because I free the memory at the end of the program.</p>
  <p>I would appreciate your suggestions and explanations.</p>