Skip to content

kokoro: Fix double free #85

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

danielzgtg
Copy link
Collaborator

@danielzgtg danielzgtg commented Jun 3, 2025

kokoro_model was being freed twice, firstly by kokoro_duration_runner while in use by kokoro_runner, which then had a use-after-free when it tried to properly free it. kokoro_context was also double-freeing some backend data that its base class runner_context would later free again. There was a mismatched new/free in prepare_post_load.

After removing the double-free, I chose to add unique_ptr to let this part hold on to RAII and ownership. reference_wrapper is instead used in another PR to indicate non-ownership. Nearby pointers have not been upgraded to unique_ptr, because they involve backends, the situation of which has been difficult to untangle.

Before, there was a SIGSEGV on post-args-refactor server shutdown. After, there the server exits cleanly on Ctrl+C. This isn't visible on the main branch, which just leaks the memory.

This also fixes the conditional prompt code blindly assuming Parler.

@danielzgtg danielzgtg changed the title Fix/kokoro double free kokoro: Fix double free Jun 3, 2025
It's been a few weeks and no opposition surfaced. This change allows
new code to be written faster and less cluttered.
kokoro_model was being freed twice, firstly by
kokoro_duration_runner while in use by kokoro_runner, which then had a
use-after-free when it tried to properly free it.
kokoro_context was also double-freeing some backend data that
its base class runner_context would later free again.
There was a mismatched new/free in prepare_post_load.

After removing the double-free, I chose to add unique_ptr to let this
part hold on to RAII and ownership. reference_wrapper is instead used in
another PR to indicate non-ownership. Nearby pointers have not been
upgraded to unique_ptr, because they involve backends, the situation of
which has been difficult to untangle.

Before, there was a SIGSEGV on post-args-refactor server shutdown.
After, there the server exits cleanly on Ctrl+C.
This isn't visible on the main branch, which just leaks the memory.
@danielzgtg danielzgtg force-pushed the fix/kokoro-double-free branch from e4122e5 to d1399e8 Compare June 3, 2025 13:53
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