Skip to content

[embedded] Fix a memory leak caused by incorrect refcounting logic around doNotFreeBit #77121

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

Merged
merged 1 commit into from
Oct 21, 2024

Conversation

kubamracek
Copy link
Contributor

Looks like we had a major memory leak caused by the changes from #76231. We can't set the refcount to HeapObject.immortalRefCount (0xffff_ffff) because that (accidentally) also includes HeapObject.doNotFreeBit (0x8000_000). Let's separate the two -- immortalRefCount is now only 0x7fff_ffff and the highest bit is used as a doNotFreeBit regardless of whether the refcount is immortal or not.

Fixes #76998

@kubamracek
Copy link
Contributor Author

@swift-ci please test

Copy link
Member

@rauhul rauhul left a comment

Choose a reason for hiding this comment

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

IIUC this seems like the approach I mentioned last time we talked about this, right? regardless thanks for the bug fix!

@mikeash
Copy link
Contributor

mikeash commented Oct 21, 2024

I'm not quite following how this works, can you explain a bit? It doesn't look like HeapObject.doNotFreeBit is checked anyhwere and I'm not sure what the intended difference is between immortal and do-no-tfree.

Copy link
Contributor

@mikeash mikeash left a comment

Choose a reason for hiding this comment

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

Sorry, wrote that question before I saw your other PR that documents it #77131. It all makes sense now.

@kubamracek kubamracek merged commit f766900 into swiftlang:main Oct 21, 2024
5 checks passed
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.

Embedded Swift string interpolation memory leak
4 participants