Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw 1.1 writer now clears encoding buffer on flush() #871

Merged
merged 3 commits into from
Dec 5, 2024
Merged

Conversation

zslayton
Copy link
Contributor

@zslayton zslayton commented Dec 5, 2024

Fixes #865.

The raw writer has an encoding buffer stored in its bump allocator.
As values are written, their serialized bytes are written to the encoding buffer.
When flush() is called, the encoding buffer's bytes are copied to output and the bump allocator is reset.
However, the writer was not clearing the encoding_buffer_ptr, which continued to refer to a (now invalid) memory region in the bump.
That memory still contained the old encoding buffer and so would result in the old data being written out again.

The 1.0 writer had the correct behavior and a cleaner implementation in general, so I copied it over.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Comment on lines +82 to +83
// Now that we've written the encoding buffer's contents to output, clear it.
self.encoding_buffer_ptr = None;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was missing in the original impl, resulting in a dangling pointer. The second time flush() was called, the match arm on the old line 77 would incorrectly be taken.

Base automatically changed from delimited-arg-group to main December 5, 2024 18:08
@zslayton zslayton merged commit 4131347 into main Dec 5, 2024
34 of 35 checks passed
@zslayton zslayton deleted the bugfix-flush branch December 5, 2024 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v1_1 Writer::flush() seems to not empty the buffer, resulting in ever-growing repeated preambles
2 participants