Your error is here:
realloc( Val_, sizeof(double) * MC.ValLength_ );
realloc( Val_, sizeof(double) * MC.ValLength_ );
To copy to clipboard, switch view to plain text mode
Realloc can move the memory block to a new mem location when extending, if there is not enough room at the current location. You missed the fact that the new address is returned by realloc. Therefore you should have:
Val_ = (double *)realloc( Val_, sizeof(double) * MC.ValLength_ );
Val_ = (double *)realloc( Val_, sizeof(double) * MC.ValLength_ );
To copy to clipboard, switch view to plain text mode
Bookmarks