diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2023-08-30 17:26:56 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2023-08-30 17:26:56 -0700 |
commit | c91c9e5eeae06a7cbed94354d62c1281dc356407 (patch) | |
tree | a589ab8716cba804ec7c60e5882a2eec7f0033b7 /src/modules/signals | |
parent | 20d097ab1fe8ef5b62f4169f4353cc0074c27e4b (diff) |
modules/*: til_module_context_free() error paths
Several modules still had vestigial ad-hoc free() cleanups on
error paths in their create_context().
Largely mechanical change of replacing those with
til_module_context_free() which is more appropriate, since the
til_module_context_t holds a reference on the setup. A plain
free() will leak that reference.
But it's only on create_context() failures which are uncommon,
so this was in practice mostly harmless...
Diffstat (limited to 'src/modules/signals')
-rw-r--r-- | src/modules/signals/signals.c | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/src/modules/signals/signals.c b/src/modules/signals/signals.c index c56c6f8..76fe4f6 100644 --- a/src/modules/signals/signals.c +++ b/src/modules/signals/signals.c @@ -38,7 +38,7 @@ static til_module_context_t * signals_create_context(const til_module_t *module, ctxt->signals[0] = sig_new_sin(sig_new_const(.5f)); /* oscillate @ .5hz */ if (!ctxt->signals[0]) - goto err; + return til_module_context_free(&ctxt->til_module_context); ctxt->signals[1] = sig_new_sin( /* oscillate */ sig_new_scale( /* at a scaled frequency */ @@ -48,7 +48,7 @@ static til_module_context_t * signals_create_context(const til_module_t *module, ) ); if (!ctxt->signals[1]) - goto err; + return til_module_context_free(&ctxt->til_module_context); ctxt->signals[2] = sig_new_lerp( /* interpolate */ sig_new_sin(sig_new_const(.33f)), /* a .33hz oscillator */ @@ -56,21 +56,21 @@ static til_module_context_t * signals_create_context(const til_module_t *module, sig_new_sin(sig_new_const(2.f)) /* weighted by a 2hz oscillator */ ); if (!ctxt->signals[2]) - goto err; + return til_module_context_free(&ctxt->til_module_context); ctxt->signals[3] = sig_new_pow( /* raise */ sig_new_sin(sig_new_const(4.f)), /* a 4hz oscillator */ sig_new_sin(sig_new_const(.33f)) /* to the power of a .33f hz oscillator */ ); if (!ctxt->signals[3]) - goto err; + return til_module_context_free(&ctxt->til_module_context); ctxt->signals[4] = sig_new_mult( /* multiply */ sig_new_sin(sig_new_const(4.f)), /* a 4hz oscillator */ sig_new_sin(sig_new_const(1.f)) /* by a 1hz oscillator */ ); if (!ctxt->signals[4]) - goto err; + return til_module_context_free(&ctxt->til_module_context); ctxt->signals[5] = sig_new_lerp( /* interpolate */ sig_ref(ctxt->signals[3]), /* signals[3] */ @@ -78,7 +78,7 @@ static til_module_context_t * signals_create_context(const til_module_t *module, sig_ref(ctxt->signals[2]) /* weighted by signals[2] */ ); if (!ctxt->signals[5]) - goto err; + return til_module_context_free(&ctxt->til_module_context); ctxt->signals[6] = sig_new_lerp( /* interpolate */ sig_new_inv(sig_ref(ctxt->signals[5])), /* invert of signals[5] */ @@ -87,21 +87,21 @@ static til_module_context_t * signals_create_context(const til_module_t *module, sig_ref(ctxt->signals[2]) /* weighted by signals[2] */ ); if (!ctxt->signals[6]) - goto err; + return til_module_context_free(&ctxt->til_module_context); ctxt->signals[7] = sig_new_mult( /* multiply */ sig_ref(ctxt->signals[6]), /* signals[6] */ sig_ref(ctxt->signals[5]) /* signals[5] */ ); if (!ctxt->signals[7]) - goto err; + return til_module_context_free(&ctxt->til_module_context); ctxt->signals[8] = sig_new_mult( /* multiply */ sig_ref(ctxt->signals[1]), /* signals[1] */ sig_ref(ctxt->signals[7]) /* signals[7] */ ); if (!ctxt->signals[8]) - goto err; + return til_module_context_free(&ctxt->til_module_context); ctxt->signals[9] = sig_new_pow( /* raise */ sig_ref(ctxt->signals[3]), /* signals[3] */ @@ -112,7 +112,7 @@ static til_module_context_t * signals_create_context(const til_module_t *module, ) ); if (!ctxt->signals[9]) - goto err; + return til_module_context_free(&ctxt->til_module_context); ctxt->signals[10] = sig_new_lerp( /* interpolate */ sig_ref(ctxt->signals[9]), /* signals[9] */ @@ -125,17 +125,9 @@ static til_module_context_t * signals_create_context(const til_module_t *module, ) ); if (!ctxt->signals[10]) - goto err; + return til_module_context_free(&ctxt->til_module_context); return &ctxt->til_module_context; - -err: - for (unsigned i = 0; i < N_SIGNALS; i++) - sig_free(ctxt->signals[i]); - - free(ctxt); - - return NULL; } |