[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Rework the do_list_voices function, and fix a memory leak.
From: |
Christopher Brannon |
Subject: |
[PATCH] Rework the do_list_voices function, and fix a memory leak. |
Date: |
Thu, 16 Sep 2010 08:13:52 -0500 |
Thanks to Jose Vilmar Estacio de Souza for sending the original patch
to fix the memory leak in this function.
We were using a GString to accumulate data, and we weren't
freeing the unused portion of that string.
I also eliminated needless copying of dynamic strings, and I
re-structured a for-loop to improve clarity.
We now ignore voices with a NULL in the name field, though this should
never happen. Also, I fixed a typo: sens -> send.
---
src/modules/module_utils.c | 24 +++++++++++++++---------
1 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/modules/module_utils.c b/src/modules/module_utils.c
index b6d938f..3ab99d2 100644
--- a/src/modules/module_utils.c
+++ b/src/modules/module_utils.c
@@ -457,20 +457,26 @@ do_list_voices(void)
}
voice_list = g_string_new("");
- for (i=0; ;i++){
- if (voices[i] == NULL) break;
- if (voices[i]->language==NULL) lang=strdup("none");
- else lang=strdup(voices[i]->language);
- if (voices[i]->dialect==NULL) dialect=strdup("none");
- else dialect=strdup(voices[i]->dialect);
+ for (i=0; voices[i] != NULL; i++){
+ if (voices[i]->name == NULL) { /* Shouldn't happen! */
+ DBG("Unnamed voice found; ignoring it.");
+ continue;
+ }
+ if (voices[i]->language==NULL)
+ lang = "none";
+ else
+ lang = voices[i]->language;
+ if (voices[i]->dialect==NULL)
+ dialect= "none";
+ else
+ dialect = voices[i]->dialect;
g_string_append_printf(voice_list, "200-%s %s %s\n", voices[i]->name,
lang, dialect);
- xfree(lang); xfree(dialect);
}
g_string_append(voice_list, "200 OK VOICE LIST SENT");
- DBG("Voice prepared to sens to speechd");
+ DBG("Voice prepared to send to speechd");
- return voice_list->str;
+ return g_string_free(voice_list, FALSE);
}
#undef SET_PARAM_NUM
--
1.7.2.3
- [PATCH] Rework the do_list_voices function, and fix a memory leak., Christopher Brannon, 2010/09/13
- [PATCH] Rework the do_list_voices function, and fix a memory leak., Andrei Kholodnyi, 2010/09/15
- [PATCH] Rework the do_list_voices function, and fix a memory leak., Christopher Brannon, 2010/09/15
- [PATCH] Rework the do_list_voices function, and fix a memory leak., Andrei Kholodnyi, 2010/09/16
- [PATCH] Rework the do_list_voices function, and fix a memory leak., Trevor Saunders, 2010/09/16
- [PATCH] Rework the do_list_voices function, and fix a memory leak., Andrei Kholodnyi, 2010/09/17
- [PATCH] Rework the do_list_voices function, and fix a memory leak., Trevor Saunders, 2010/09/17
- [PATCH] Rework the do_list_voices function, and fix a memory leak.,
Christopher Brannon <=
- [PATCH] Rework the do_list_voices function, and fix a memory leak., Andrei . Kholodnyi, 2010/09/16
- [PATCH] Rework the do_list_voices function, and fix a memory leak., William Hubbs, 2010/09/16
- [PATCH] Rework the do_list_voices function, and fix a memory leak., Christopher Brannon, 2010/09/16
- [PATCH] Rework the do_list_voices function, and fix a memory leak., Andrei Kholodnyi, 2010/09/16
- [PATCH] Rework the do_list_voices function, and fix a memory leak., Christopher Brannon, 2010/09/16