Fix memory leak in Signature.decode() #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Signature.decode()
followed bySignature.deinit()
leaked memory.My best guess for why this was happening is that there is a pointer somewhere in the internals of
std.heap.ArenaAllocator
that gets invalidated when theArenaAllocator
is copied from the function scope into theSignature
and returned fromSignature.decode()
. However, I'm not familiar enough withArenaAllocator
's internals to be confident in that.I solved the issue by removing the
ArenaAllocator
and using the suppliedstd.mem.Allocator
directly. This required the following:Allocator.dupe()
calls before of the struct initialization so that they may have their ownerrdefer
'd calls toAllocator.free()
. Strictly speaking, only the firsterrdefer
is necessary, since there are no more opportunities for errors following the second call toAllocator.dupe()
, but I've included both in case the code is rearranged in the future.ArenaAllocator
field inSignature
with a plainAllocator
.trusted_comment
anduntrusted_comment
fields individually inSignature.deinit()
.