Title: ArgConverter::SetValue: invalid pointer for a JS number or boolean in an object slot, and a leaked adapter for a plain object from an unowned method · Issue #572 · NativeScript/ios · GitHub
Open Graph Title: ArgConverter::SetValue: invalid pointer for a JS number or boolean in an object slot, and a leaked adapter for a plain object from an unowned method · Issue #572 · NativeScript/ios
X Title: ArgConverter::SetValue: invalid pointer for a JS number or boolean in an object slot, and a leaked adapter for a plain object from an unowned method · Issue #572 · NativeScript/ios
Description: Summary ArgConverter::SetValue writes the result of a JS-implemented method, getter or block into the native return slot. For some combinations of JS value and native return type it writes nothing, or writes something that is not a valid...
Open Graph Description: Summary ArgConverter::SetValue writes the result of a JS-implemented method, getter or block into the native return slot. For some combinations of JS value and native return type it writes nothing,...
X Description: Summary ArgConverter::SetValue writes the result of a JS-implemented method, getter or block into the native return slot. For some combinations of JS value and native return type it writes nothing,...
Opengraph URL: https://github.com/NativeScript/ios/issues/572
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ArgConverter::SetValue: invalid pointer for a JS number or boolean in an object slot, and a leaked adapter for a plain object from an unowned method","articleBody":"## Summary\n\n`ArgConverter::SetValue` writes the result of a JS-implemented method, getter or block into the native return slot. For some combinations of JS value and native return type it writes nothing, or writes something that is not a valid value of that type, and native code then reads it.\n\n| JS result | Native return type | What is written |\n|---|---|---|\n| number | object (`id`, a class, `instancetype`) | nothing: the slot keeps whatever it held |\n| `true` | object | the integer 1, which native code treats as an object pointer |\n| `false` | object | 0, which reads as nil |\n| string | `instancetype` | nothing |\n\nA string returned for an `id` or class-typed result is converted to an `NSString`, and `null`/`undefined` zero the slot; those are fine.\n\n```js\nconst X = NSObject.extend({\n description() { return 42; }, // NSString* expected: the slot is not written\n});\n```\n\nThe caller then messages a garbage pointer, or `0x1`. This is a mistake in the JS implementation, but the runtime should fail predictably and not hand native code an arbitrary pointer.\n\n## A plain JS object from a method that doesn't own its return leaks its adapter\n\nA related gap in the same function. For a plain JS object (or an array, function or Date) returned where an object is expected, `SetValue` creates a `DictionaryAdapter` with `alloc`/`init` and writes it at +1. A `CFAutorelease(adapter)` next to it is commented out.\n\nThat +1 is right when the method owns its return (the `copy`, `mutableCopy` and `new` families, initializers), and since #569 those are balanced. For any other method the native caller doesn't own the result and never releases it, so the adapter is never freed and its `Persistent` keeps the JS object alive:\n\n```js\nconst X = NSObject.extend({ makeThing() { return {}; } }, {\n exposedMethods: { makeThing: { returns: NSObject } },\n});\n// a native caller of -makeThing: the adapter and the object it wraps are never freed\n```\n\nSeen with a `WeakRef` on the returned object, which never clears after a native `performSelector:` call.\n\nThe fix is to hand the adapter over at +0 (autoreleased) when the method doesn't own its return. `SetValue` already reports whether it wrote an object the caller doesn't own; it would need to distinguish \"wrote a +1 object\" from \"wrote nothing\" so the caller can autorelease in the unowned case.\n\n## Suggested fix\n\nIn `ArgConverter::SetValue`, for object return types:\n\n- box a JS number or boolean as an `NSNumber`, as argument marshalling already does for a number passed to an object parameter (`Interop::SetFFIParams`), or write nil if boxing is not wanted there;\n- convert a string for `instancetype` as for `id`, or write nil;\n- in every other case that has no conversion, zero the slot.\n\nThe function has a `TODO` about reusing `Interop::SetFFIParams`; sharing that logic would fix all of these at once.\n\nWhatever is boxed is returned at +0, so it also has to go through the owned-result retain added in #569 (`ArgConverter::RetainOwnedResult`), which today only recognises wrapped objects and strings.\n\n## Tests to add\n\n- A JS method declared to return an object that returns a number, `true`, and `false`: a native caller gets an `NSNumber` (or nil), never an invalid pointer. Run under AddressSanitizer.\n- A JS initializer (`instancetype`) that returns a string: the native caller gets nil or an `NSString`, not an unwritten slot.\n- The same through an owned-return method (`copyWithZone:`), checking the count of the boxed result.\n- A JS method that doesn't own its return, returning a fresh plain object to a native caller: a `WeakRef` on the object clears once the caller's autorelease pool drains.\n\nFound while reviewing #569; not reproduced in a spec yet, because in Debug builds some of these paths assert first.\n\n","author":{"url":"https://github.com/edusperoni","@type":"Person","name":"edusperoni"},"datePublished":"2026-11-15T16:12:10Z","url":"https://github.com/NativeScript/ios/issues/572"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a692cf2c-bcbc-4214-ff6f-bcb792d51ee0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC86:2454CC:160C473:1BFC089:6B01357D |
| html-safe-nonce | 938d73207189ebe8702d602953f3eaa5a95d6fff06691385f8cacd0157bdf7c0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzg2OjI0NTRDQzoxNjBDNDczOjFCRkMwODk6NkIwMTM1N0QiLCJ2aXNpdG9yX2lkIjoiNTk5MzI4OTUwNjU2NzA0MjQyOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 61c85dd48a668142590516090cd1794327748e6904fc3b0292eb91eb305a67ed |
| hovercard-subject-tag | issue:6406314860 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/ios/572/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0dc299817264a0daf99a6f8aa8e5316ddbf33aa56165910b9283869d6b0b8381/NativeScript/ios/issues/572 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0dc299817264a0daf99a6f8aa8e5316ddbf33aa56165910b9283869d6b0b8381/NativeScript/ios/issues/572 |
| og:image:alt | Summary ArgConverter::SetValue writes the result of a JS-implemented method, getter or block into the native return slot. For some combinations of JS value and native return type it writes nothing,... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | edusperoni |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/ios git https://github.com/NativeScript/ios.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 172934359 |
| octolytics-dimension-repository_nwo | NativeScript/ios |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 172934359 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/ios |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width