Skip to content
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

[Archive C++ wrapper] context wild pointer #1746

Open
WorkingChen opened this issue Feb 17, 2025 · 0 comments
Open

[Archive C++ wrapper] context wild pointer #1746

WorkingChen opened this issue Feb 17, 2025 · 0 comments

Comments

@WorkingChen
Copy link
Contributor

When using cpp_wrapper AeronArchive::connect(globalCtx), it appears that a new Context is recreated within the AeronArchive::connect method. This Context object has own_aeron_client = false, but when the Context object is destroyed, it also deletes the memory of *aeron_t. This will cause globalCtx to be unusable afterward, as globalCtx.m_aeron_archive_ctx_t.aeron becomes a dangling pointer. Calling AeronArchive::connect(globalCtx) again will result in a memory access error. Is it necessary to warn users that the context can only be used within the method and should only be used once?

file: aeron_archive_async_connect.c
method: aeron_archive_async_connec
line:aeron_archive_context_duplicate

`
int aeron_archive_async_connect(aeron_archive_async_connect_t **async, aeron_archive_context_t *ctx)
{
// ...

if (aeron_archive_context_duplicate(&_async->ctx, ctx) < 0)
{
    AERON_APPEND_ERR("%s", "");
    aeron_free(_async);
    return -1;
}

// Now that we've copied the original context into the _async->ctx, the original ctx no longer owns the aeron client.
aeron_archive_context_set_owns_aeron_client(ctx, false);
// ...
*async = _async;

return 0;

}
`

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

No branches or pull requests

1 participant