Here is the code for this example (source):
// Created for COMP2521 UNSW sanitisers guide
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int *zeroes = calloc(10, sizeof(int));
free(zeroes);
free(zeroes);
}
This code allocates an array of zeroes, then frees this array, then attempts to free it again.
Here is the error message:
main()
free(zeroes)
;main()
free(zeroes);
main()
calloc()
to allocate the arrayFrom the error message, we can see that the error comes from trying to free the zeroes()
array twice - once on line 7 and then again on line 8.
Remove one of the free()
s.