mirror of
https://github.com/linux-speakup/espeakup.git
synced 2026-08-22 15:44:17 +02:00
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:
parent
58f09983f8
commit
a82bbd8140
1 changed files with 22 additions and 19 deletions
41
synth.c
41
synth.c
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue