diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2021-07-19 14:58:23 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-07-23 21:08:05 -0400 |
commit | 509445b5947ce85499672399f5e88b6196af4c5a (patch) | |
tree | 167870cdb6526452cc5156d6f75c3294c17e70bc /compiler/GHC/Tc/Gen/Splice.hs | |
parent | 4beb12dbc4a7c42c3967dd51da769a3346192a1b (diff) | |
download | haskell-509445b5947ce85499672399f5e88b6196af4c5a.tar.gz |
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
`act`.
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
Diffstat (limited to 'compiler/GHC/Tc/Gen/Splice.hs')
0 files changed, 0 insertions, 0 deletions