ref: b763f63edd01b4a22c2a122810f60009beafd40c
parent: 1b550b87f65fcf414c5fa0f44a272491c6e5acc3
author: cbagwell <cbagwell>
date: Tue Aug 19 21:58:31 EDT 2008
Fixe memory leaks in effects chain when restarting effects.
--- a/ChangeLog
+++ b/ChangeLog
@@ -39,7 +39,7 @@
o Allow libsamplerate to be found if pkg-config is installed but
no samplerate.pc exists. (cbagwell)
o [2038855] external lpc10 lib patch. (Oden Eriksson, Mandriva)
-
+ o Fix memory leaks in effects chain when restarting effects.
sox-14.1.0 2008-7-29
----------
--- a/src/effects.c
+++ b/src/effects.c
@@ -362,39 +362,52 @@
return clips;
}
-sox_size_t sox_stop_effect(sox_effects_chain_t * chain, sox_size_t e)
+sox_size_t sox_stop_effect(sox_effect_t *effp)
{
unsigned f;
- sox_effect_t * effp = &chain->effects[e][0];
sox_size_t clips = 0;
for (f = 0; f < effp->flows; ++f) {
- effp->handler.stop(&chain->effects[e][f]);
- clips += chain->effects[e][f].clips;
+ effp[f].handler.stop(&effp[f]);
+ clips += effp[f].clips;
}
return clips;
}
-/* Remove all effects from the chain */
+/* Free resources related to effect.
+ * Note: This currently closes down the effect which might
+ * note be obvious from name.
+ */
+static void sox_delete_effect(sox_effect_t *effp)
+{
+ sox_size_t clips;
+ unsigned f;
+
+ if ((clips = sox_stop_effect(effp)) != 0)
+ sox_warn("%s clipped %u samples; decrease volume?",
+ effp->handler.name, clips);
+ for (f = 0; f < effp->flows; ++f)
+ {
+ effp[f].handler.kill(&effp[f]);
+ free(effp[f].priv);
+ free(&effp[f]);
+ }
+}
+
+/* Remove all effects from the chain.
+ * Note: This currently closes down the effect which might
+ * note be obvious from name.
+ */
void sox_delete_effects(sox_effects_chain_t * chain)
{
- sox_size_t e, clips;
- unsigned f;
+ sox_size_t e;
for (e = 0; e < chain->length; ++e) {
- sox_effect_t * effp = chain->effects[e];
- if ((clips = sox_stop_effect(chain, e)) != 0)
- sox_warn("%s clipped %u samples; decrease volume?",
- chain->effects[e][0].handler.name, clips);
- effp->handler.kill(effp);
- for (f = 0; f < effp->flows; ++f)
- free(chain->effects[e][f].priv);
- free(effp);
+ sox_delete_effect(chain->effects[e]);
+ chain->effects[e] = NULL;
}
chain->length = 0;
}
-
-
/* Effects library: */
--- a/src/sox.h
+++ b/src/sox.h
@@ -500,7 +500,7 @@
int sox_add_effect( sox_effects_chain_t * chain, sox_effect_t * effp, sox_signalinfo_t * in, sox_signalinfo_t const * out);
int sox_flow_effects(sox_effects_chain_t *, int (* callback)(sox_bool all_done));
sox_size_t sox_effects_clips(sox_effects_chain_t *);
-sox_size_t sox_stop_effect(sox_effects_chain_t *, sox_size_t e);
+sox_size_t sox_stop_effect(sox_effect_t *effp);
void sox_delete_effects(sox_effects_chain_t *);
/* The following routines are unique to the trim effect.