title: Free list of integers
body: <p>I was trying to free a list of integers starting from the head and knowing how many elements are in the list, but I am getting an invalid pointer error.
  The code is the following:</p>
  <pre><code>int* factors = job_factorization(number, size);
  printf(&quot;Thread %d: job terminated. Result: &quot;, params-&gt;thread_id);
  int* tmp;
  for (int i = 0; i &lt; *size; i++){
      printf(&quot;%d &quot;, *factors);
      tmp = factors;
      factors++;
      free(tmp);
  }
  
  int *job_factorization(int number, int *size) {
      int *factors;
      int array_size = SIZE_INCREASE;
      int factor = 2;
  
      if (number &lt; 2)
          return NULL;
  
      factors = (int *) malloc(sizeof(int) * SIZE_INCREASE);
      *size = 0;
  
      while (number != 1) {
          // check whether the number is divisible by the factor
          if (number % factor == 0) {
              // if there is no more space available, resize the array
              if (*size == array_size) {
                  array_size += SIZE_INCREASE;
                  factors = (int *) realloc(factors, sizeof(int) * array_size);
              }
              // add the factor to the list of prime factors
              factors[*size] = factor;
              (*size)++;
              number = number / factor;
          }
          else {
              // if not a factor, move to the next prime number
              factor = next_prime(factor);
          }
      }
      return factors;
  }
  </code></pre>
  <p>Does anyone have any idea of the reason why this is happening? I have no clue about it (the function job_factorization works correctly)</p>