Increase dc_context_t reference count during dc_configure()

This fixes use-after-free in case dc_context_unref() is called
while the background process spawned by dc_configure() is still
running.

Corresponding regression test in Python can be run with
`pytest tests/test_1_online.py::test_configure_unref`.
This commit is contained in:
link2xt
2023-03-13 12:14:55 +00:00
parent 5805f99acd
commit 30fef395b4

View File

@@ -428,9 +428,10 @@ pub unsafe extern "C" fn dc_configure(context: *mut dc_context_t) {
return;
}
let ctx = &*context;
// Clone the context Arc so we do not use the reference after dc_configure() returns.
let ctx = (*context).clone();
spawn(async move { ctx.configure().await.log_err(ctx, "Configure failed") });
spawn(async move { ctx.configure().await.log_err(&ctx, "Configure failed") });
}
#[no_mangle]