Skip to content

fix(ffi): don't steal Arc in dc_jsonrpc_init#7962

Merged
d2weber merged 1 commit intomainfrom
d2weber/fix_double_free
Mar 7, 2026
Merged

fix(ffi): don't steal Arc in dc_jsonrpc_init#7962
d2weber merged 1 commit intomainfrom
d2weber/fix_double_free

Conversation

@d2weber
Copy link
Collaborator

@d2weber d2weber commented Mar 6, 2026

This is a follow up PR for #7961 to allow for CI to run correctly

dc_jsonrpc_init called Arc::from_raw on the account_manager pointer,
which took ownership of the caller's refcount. When the local Arc
dropped at the end of the function, the refcount was decremented,
leaving the C side's pointer with a stolen refcount. This caused a
use-after-free race between dc_accounts_unref and dc_jsonrpc_unref
at shutdown.

Wrap in ManuallyDrop to prevent the implicit drop, keeping the
caller's refcount intact.

Regression introduced in #7662.
@d2weber
Copy link
Collaborator Author

d2weber commented Mar 6, 2026

CI fails due to a Timeout error

@link2xt
Copy link
Collaborator

link2xt commented Mar 7, 2026

CI fails due to a Timeout error

CI is flaky, especially on macOS runners.

Copy link
Collaborator

@link2xt link2xt left a comment

Choose a reason for hiding this comment

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

Looks good. For reference, seems there is no better way: https://stackoverflow.com/questions/77947159/idiomatic-usage-of-arc-in-c-ffi

@link2xt link2xt added the blocker label Mar 7, 2026
@link2xt
Copy link
Collaborator

link2xt commented Mar 7, 2026

We should merge it before release.

@d2weber d2weber merged commit a95bf77 into main Mar 7, 2026
77 of 85 checks passed
@d2weber d2weber deleted the d2weber/fix_double_free branch March 7, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants