Skip to content

prototype refcount fixes - #497

Open
nbd168 wants to merge 2 commits into
ucode-lang:masterfrom
nbd168:ref-fixes
Open

nbd168 wants to merge 2 commits into
ucode-lang:masterfrom
nbd168:ref-fixes

Conversation

@nbd168

@nbd168 nbd168 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor
  • fix extra reference on the prototype in proto()
  • release old instance prototype of a resource

ucv_prototype_set() keeps the reference it is given. Since commit
c3dc162 ("lib: reject circular prototype chains in proto()"),
uc_proto() passes it an owned reference, but it still takes the second
reference that used to balance the borrowed one. Each successful
proto(value, prototype) call thus leaks one reference on the prototype,
which is then never freed.

Drop the extra reference, and test that a prototype holds exactly one
reference per value that uses it.

Fixes: c3dc162 ("lib: reject circular prototype chains in proto()")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Comment thread tests/custom/17_lib_ffi/32_proto Outdated
@@ -0,0 +1,30 @@
Setting the prototype of a library handle releases the previous one.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd rather fold this testcase into the existing generic 40_proto one and make it skip itself if require("ffi") fails. You can acquire ffi.C from the scope returned by require().

For an extended resource with an instance prototype slot,
ucv_prototype_set() overwrites the slot without a release of the
prototype it holds. The resource owns that reference, since the free
path puts every value slot, so each proto(resource, prototype) call
leaks the earlier prototype. Reachable from script for ffi library
handles, for example proto(ffi.C, {}).

Store the prototype with ucv_resource_proto_set(), which releases the
earlier value, like the array and object cases do.

Fixes: c404fe2 ("types: add per-instance prototype support for extended resources")
Signed-off-by: Felix Fietkau <nbd@nbd.name>

This branch has not been deployed

No deployments
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.

2 participants