diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2023-01-19 21:00:40 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2023-01-20 00:20:15 -0800 |
commit | 5e647dee95763d8f628bdc771a32c5d33c51d78a (patch) | |
tree | 399fcda4edda0a9c5017aff784b09c80110804f9 /src/til.c | |
parent | 729ea9c0f2d6a9caa27f17c05e0c26560a8f07e1 (diff) |
til: pass module to .context_create()/til_module_context_new()
Let's make it so til_module_context_t as returned from
til_module_context_new() can immediately be freed via
til_module_context_free().
Previously it was only after the context propagated out to
til_module_context_create() that it could be freed that way, as
that was where the module member was being assigned.
With this change, and wiring up the module pointer into
til_module_t.create_context() as well for convenient providing to
til_module_context_new(), til_module_t.create_context() error
paths can easily cleanup via `return til_module_context_free()`
But this does require the til_module_t.destroy_context() be able
to safely handle partially constructed contexts, since the
mid-create failure freeing won't necessarily have all the members
initialized. There will probably be some NULL derefs to fix up,
but at least the contexts are zero-initialized @ new.
Diffstat (limited to 'src/til.c')
-rw-r--r-- | src/til.c | 11 |
1 files changed, 3 insertions, 8 deletions
@@ -248,17 +248,12 @@ int til_module_create_context(const til_module_t *module, til_stream_t *stream, n_cpus = til_threads_num_threads(til_threads); if (!module->create_context) - context = til_module_context_new(stream, sizeof(til_module_context_t), seed, ticks, n_cpus, path); + context = til_module_context_new(module, sizeof(til_module_context_t), stream, seed, ticks, n_cpus, path); else - context = module->create_context(stream, seed, ticks, n_cpus, path, setup); - - if (!context) { - free(path); + context = module->create_context(module, stream, seed, ticks, n_cpus, path, setup); + if (!context) return -ENOMEM; - } - - context->module = module; *res_context = context; |