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

Memory ownership destroyed for unknown reason #119

Open
Scooletz opened this issue Aug 7, 2023 · 1 comment
Open

Memory ownership destroyed for unknown reason #119

Scooletz opened this issue Aug 7, 2023 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Scooletz
Copy link
Contributor

Scooletz commented Aug 7, 2023

TransformExtension methods for some reason destroys the memory ownership and requires copying to a locally stackallocked Span. This should not be the biggest burden, but still, solving the mystery would be appreciated. The method that misbihaves is this one

private static DeleteStatus TransformExtension(in Key childKey, ICommit commit, in Key key, in Node.Extension ext)
{
using var childOwner = commit.Get(childKey);
// TODO: this should be not needed but for some reason the ownership of the owner breaks memory safety here
Span<byte> copy = stackalloc byte[childOwner.Span.Length];
childOwner.Span.CopyTo(copy);
Node.ReadFrom(copy, out var childType, out var childLeaf, out var childExt, out _);
if (childType == Node.Type.Extension)
{
// it's E->E, merge extensions into a single extension with concatenated path
commit.DeleteKey(childKey);
commit.SetExtension(key,
ext.Path.Append(childExt.Path, stackalloc byte[NibblePath.FullKeccakByteLength]));
return DeleteStatus.NodeTypePreserved;
}
// it's E->L, merge them into a leaf
commit.DeleteKey(childKey);
commit.SetLeaf(key,
ext.Path.Append(childLeaf.Path, stackalloc byte[NibblePath.FullKeccakByteLength]));
return DeleteStatus.ExtensionToLeaf;
}

Depending on the run it can throw:

  1. NullReferenceException
  2. Break CLR by pointing to some valid memory region but failing of dispose dispatch
@Scooletz Scooletz added bug Something isn't working good first issue Good for newcomers labels Aug 7, 2023
@AbhinavMir
Copy link

Should I quickly run this thru a debugger of some sort and see what's happening? I can then make a guess if I'm the right person to solve it or not. Need a day or two to set things up! Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Status: In Progress
Development

No branches or pull requests

2 participants