WiFi Library Inefficiencies?

ddod:
What's the String bug?

The String class uses dynamic memory allocation to provide the internal buffers which store the string content. The underlying memory management library has a bug which can cause memory corruption. The bug can be exposed by quite simple patterns of allocating and deallocating String objects, and sample code demonstrating this looks rather similar to what you're doing here. Since it's hard (IMO) to predict which uses of String will expose the bug and which ones won't, I suggest that you should avoid using String completely, at least until the bug has been fixed in some future release of Arduino. String is provided as a helper class but the things that can be done using String can be done using plain old c-strings instead, usually without much extra complexity.