Added a line reading function that reuses the same dynamically allocated memory.