Check the buffer size *before* calling the continuation in withEncodedCString
This fixes a very subtle bug in withEncodedCString where a reference would
be kept to the whole continuation until the continuation had finished
executing. This was because the call to tryFillBufferAndCall could fail,
if the buffer was already full and so the
go helper would be
recursively called on failure which necessitated keeping a reference to
The failure could only happen during the initial checking phase of the function but not during the call to the continuation. Therefore the fix is to first perform the size check, potentially recursively and then finally calling tail calling the continuation.
In the real world, this broke writing lazy bytestrings because a reference to the head of the bytestring would be retained in the continuation until the whole string had been written to a file.
Fixes #20107 (closed)