Not sure why you get that particular probem, but:
Code:
	if (line_buff == NULL) 
	{
	    line_buff = temp_buff;
	}
is twice in your code, and you REALLY do not want to do that - you WILL be writing over the end of your allocated memory with that - you probably should exit out of the app if you can't get the memory to produce the full string.


Another "interesting" point is that you never "recharge" chars_left when you grow the buffer, so perhaps you are really running out of memory when you reach chars_left = 0.

--
Mats