So I'm writing a program and for some reason if I leave out the free part it doesn't work in random places so I was wondering if I did something wrong.
When I leave out the free part the program runs and finishes fine, but when I leave it in, it segfaults at a random and place. What actually happens is, another unrelated pointer is modified and when its accessed I get the error, am I doing something wrong?Code:int* list = (int*)malloc(0); int num = 0; for(i=0; i < something; i++) { if(something random happens) { num++; list = (int*) realloc(list, sizeof(int*) * num); list[num - 1] = something; } } free(list);