Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactoring Bytes to check double free and code cleanup #22251

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

Open
cpegeric wants to merge 10 commits into matrixorigin:main
base: main
Choose a base branch
Loading
from cpegeric:atomic_bytes

Conversation

@cpegeric
Copy link
Contributor

@cpegeric cpegeric commented Jul 24, 2025
edited
Loading

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #22250

What this PR does / why we need it:

Bytes to check double free and code cleanup

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jul 24, 2025
Copy link
Contributor

@fengttt fengttt left a comment

Choose a reason for hiding this comment

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

Please fix the panic. Also check/verify that we always have set refcount to 1 when creating a cached "bytes".

idx := int(cacheData.Index)
if cacheData.Hit {
vector.Entries[idx].done = true
vector.Entries[idx].CachedData = &Bytes{bytes: cacheData.Data}
Copy link
Contributor

Choose a reason for hiding this comment

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

@reusee can you please check this line? This is significant. I will be surprised if the old code works, and the new code also works without a leak. Are we fixing a real bug here?

Copy link
Contributor

Choose a reason for hiding this comment

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

旧的代码不带引用计数,所以就只是对 []byte 的包装。新的代码改成了引用计数,只要使用方的计数正确,就不会有问题。如果真的有问题,可以另外增加一个 GoBytes 类型,实现 fscache.Data 接口,但不实现引用计数机制。

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. Cannot have another type; the ref counting MUST be correct. So great, let's go with this and see if we will hit panic.

Thank you.

}
bytes._refs.Store(1)
bytes.refs = &bytes._refs
bytes.refs.Store(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor, you can do a NewBytes here, so that we can restrict all the Store(1) to one single place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@fengttt fengttt fengttt approved these changes

@reusee reusee reusee approved these changes

Assignees

No one assigned

Labels

kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /