I apologize for the lengthy code. I have a simple question, but I thought I include my code so it will be clear where I am coming from. I get a realloc corruption. I think the c
glibc is telling you you're passing in an address that couldn't have been returned from malloc/realloc. This is because you're passing in the address of the pointsAndName
stack variable. You need to pass in the value, which is what you received from malloc
. Also, whenever you call realloc
, you should use a temporary variable. That way, if the realloc
fails, you still free the original value.
struct figure *tempPtr = realloc(pointsAndname, temp * sizeof(struct figure));
if(tempPtr == NULL)
{
// Handle allocation error...
free(pointsAndname);
}
pointsAndname = tempPtr;