Losing sensitive data when trying to send them via GSM
There is probably a way of doing this using "cooperative multitasking" --
a main loop that calls non-blocking functions (possibly using state machines).
Blink Without Delay shows the first steps in this direction.

Alas, lots of code has been written with blocking functions, so rather than re-write that code to be non-blocking, often people:


do the most time-sensitive stuff in an interrupt routine (the "foreground task").
handle the less time-sensitive stuff in the main loop() (the "background task").


Often the code has 2 separate buffers so it can do double-buffering:
the writer process slowly fills one buffer.
When it is full,
the reader process processes the data in that buffer -- meanwhile, the writer process slowly fills up the other buffer.
Hopefully the reader process will be done with that buffer long before the other buffer is completely full, although we expect the writer to write something to that other buffer before the reader process is done.
In your case, while you are making the TCP connection and sending out the data in one buffer,
the processor can be occasionally interrupted to let the interrupt routine add another data item to the other buffer.