From a82bbd81400cfa002835c35ce46a956cc81460ad Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sun, 28 Jun 2009 17:56:21 -0500 Subject: [PATCH] fixed a memory leak If we processed an entry from the queue successfully, we were removing the entry itself from the queue but not freeing the memory allocated to the entry. --- synth.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/synth.c b/synth.c index 28aa15c..f77960e 100644 --- a/synth.c +++ b/synth.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -143,6 +144,26 @@ static espeak_ERROR speak_text(struct synth_t * s) return rc; } +static void free_espeak_entry(struct espeak_entry_t *entry) +{ + assert(entry); + if (entry->cmd == CMD_SPEAK_TEXT) + free(entry->buf); + free(entry); +} + +static void queue_clear() +{ + struct espeak_entry_t *current; + + current = (struct espeak_entry_t *) queue_peek(); + while (current) { + free_espeak_entry(current); + queue_remove(); + current = (struct espeak_entry_t *) queue_peek(); + } +} + static void queue_process_entry(struct synth_t *s) { espeak_ERROR error; @@ -180,6 +201,7 @@ static void queue_process_entry(struct synth_t *s) } if (error == EE_OK) { + free_espeak_entry(current); pthread_mutex_lock(&queue_guard); queue_remove(); pthread_mutex_unlock(&queue_guard); @@ -187,25 +209,6 @@ static void queue_process_entry(struct synth_t *s) } } -static void free_entry(struct espeak_entry_t *entry) -{ - if (entry->cmd == CMD_SPEAK_TEXT) - free(entry->buf); - free(entry); -} - -static void queue_clear() -{ - struct espeak_entry_t *current; - - current = (struct espeak_entry_t *) queue_peek(); - while (current) { - free_entry(current); - queue_remove(); - current = (struct espeak_entry_t *) queue_peek(); - } -} - int initialize_espeak(struct synth_t *s) { int rate;