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.
This commit is contained in:
William Hubbs 2009-06-28 17:56:21 -05:00
commit a82bbd8140

41
synth.c
View file

@ -17,6 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -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;