speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] memory leak in espeak


From: José Vilmar Estácio de Souza
Subject: [PATCH] memory leak in espeak
Date: Wed, 3 Nov 2010 11:53:48 -0200

The function module_init declares and allocates a string called info
that is only used and released if the macro ABORT is called.

This patch removes the string info and slightly refactor the function
module_init to get rid of MACRO ABORT.
---
 src/modules/espeak.c |   18 ++++++------------
 1 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/modules/espeak.c b/src/modules/espeak.c
index 3c46cc9..d29be8d 100644
--- a/src/modules/espeak.c
+++ b/src/modules/espeak.c
@@ -229,19 +229,11 @@ module_load(void)
        return OK;
 }
 
-#define ABORT(msg)                                                             
\
-       g_string_append(info, msg);                                     \
-       DBG("FATAL ERROR: %s", info->str);                      \
-       *status_info = info->str;                                       \
-       g_string_free(info, FALSE);                                     \
-       return FATAL_ERROR;
-
 int
 module_init(char **status_info)
 {
        int ret;
        const char *espeak_version;
-       GString *info;
     
        DBG("Espeak: Module init().");
        INIT_INDEX_MARKING();
@@ -249,7 +241,6 @@ module_init(char **status_info)
        if (!g_thread_supported ()) g_thread_init (NULL); 
 
        *status_info = NULL;
-       info = g_string_new("");
 
        /* Report versions. */
        espeak_version = espeak_Info(NULL);
@@ -300,21 +291,24 @@ module_init(char **status_info)
        espeak_stop_or_pause_semaphore = module_semaphore_init();
        ret = pthread_create(&espeak_stop_or_pause_thread, NULL, 
_espeak_stop_or_pause, NULL);
        if(0 != ret) {
-               ABORT("Failed to create stop-or-pause thread.");
+               DBG("Failed to create stop-or-pause thread.");
+               *status_info = g_strdup("Failed to create stop-or-pause 
thread.");
+               return FATAL_ERROR;
        }
         
        espeak_play_semaphore = module_semaphore_init();
        DBG("Espeak: Creating new thread for playback.");
        ret = pthread_create(&espeak_play_thread, NULL, _espeak_play, NULL);
        if (ret != OK) {
-               ABORT("Failed to create playback thread.");
+               DBG("Failed to create playback thread.");
+               *status_info = g_strdup("Failed to create playback thread.");
+               return FATAL_ERROR;
        }
 
        *status_info = g_strdup("Espeak: Initialized successfully.");
 
        return OK;
 }
-#undef ABORT
 
 
 int
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]