[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] memory leak
From: |
José Vilmar Estácio de Souza |
Subject: |
[PATCH 2/2] memory leak |
Date: |
Sun, 28 Feb 2010 22:01:57 -0300 |
The _ibmtts_play function present in the file ibmtts.c has a loop to
remove and process commands present in playback_queue variable.
after the command is processed, the memory used by the command is released.
One condition to stop the loop is the content of the variable
ibmtts_stop_play_requested to be false.
When this happens a command could be removed but not processed, and the
memory used by the command is not released.
I tried to refactor the function slightly to avoid this situation
Also the module_init function allocates memory to the string info
but would not release at the end.
---
src/modules/ibmtts.c | 28 +++++++++++-----------------
1 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/src/modules/ibmtts.c b/src/modules/ibmtts.c
index 7169a02..f013643 100644
--- a/src/modules/ibmtts.c
+++ b/src/modules/ibmtts.c
@@ -520,6 +520,7 @@ module_init(char **status_info)
module_audio_id = NULL;
*status_info = strdup("Ibmtts: Initialized successfully.");
+ g_string_free(info, 1);
return OK;
}
@@ -1432,19 +1433,19 @@ _ibmtts_play(void* nothing)
pthread_mutex_lock(&ibmtts_play_suspended_mutex);
sem_wait(ibmtts_play_semaphore);
pthread_mutex_unlock(&ibmtts_play_suspended_mutex);
- if (ibmtts_thread_exit_requested) break;
}
/* DBG("Ibmtts: Playback semaphore on."); */
- pthread_mutex_lock(&playback_queue_mutex);
- if (NULL != playback_queue) {
- playback_queue_entry = playback_queue->data;
- playback_queue = g_slist_remove(playback_queue,
playback_queue->data);
- }
- pthread_mutex_unlock(&playback_queue_mutex);
-
- while ((NULL != playback_queue_entry) && !ibmtts_stop_play_requested)
+ while (!ibmtts_stop_play_requested && !ibmtts_thread_exit_requested)
{
+ pthread_mutex_lock(&playback_queue_mutex);
+ if (NULL != playback_queue) {
+ playback_queue_entry = playback_queue->data;
+ playback_queue = g_slist_remove(playback_queue,
playback_queue->data);
+ }
+ pthread_mutex_unlock(&playback_queue_mutex);
+ if (NULL == playback_queue_entry) break;
+
switch (playback_queue_entry->type) {
case IBMTTS_QET_AUDIO:
ibmtts_send_to_audio(playback_queue_entry);
@@ -1483,14 +1484,7 @@ _ibmtts_play(void* nothing)
ibmtts_delete_playback_queue_entry(playback_queue_entry);
playback_queue_entry = NULL;
-
- pthread_mutex_lock(&playback_queue_mutex);
- if (NULL != playback_queue) {
- playback_queue_entry = playback_queue->data;
- playback_queue = g_slist_remove(playback_queue,
playback_queue->data);
- }
- pthread_mutex_unlock(&playback_queue_mutex);
- }
+ }
if (ibmtts_stop_play_requested) DBG("Ibmtts: Stop or pause in
playback thread.");
}
--
1.6.3.3
--------------060902000005080603050908--
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH 2/2] memory leak,
José Vilmar Estácio de Souza <=