Fixed invalid argument for realloc.
Fixed missing do in loop.