double free or corruption
The program attempts to free memory that has already been freed.
free on the same pointer twicemalloc/callocint main() {
int *ptr = malloc(sizeof(int));
free(ptr);
free(ptr); // Double free
return 0;
}Set pointers to NULL after freeing them and check before freeing.
int main() {
int *ptr = malloc(sizeof(int));
if (ptr != NULL) {
free(ptr);
ptr = NULL; // Set to NULL after freeing
}
// If we try to free again, check first
if (ptr != NULL) {
free(ptr);
ptr = NULL;
}
return 0;
}NULL after freeing themNULL before freeing it