StringRead() allocates a few resources and normally releases them at the end of the function. But there are cases where StringRead() returns early due to an error, e.g. failure to allocate a particular resource. In some of these cases, that leads to other resources being leaked.
The attached patch attempts to resolve this, however I have not tested it on Windows. I wonder if it would be better to use a goto cleanup approach.
Used goto approach.
Tested on Windows and Linux.