[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: |
Mon, 13 Sep 2010 17:27:01 -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.
---
src/modules/module_utils.c | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/modules/module_utils.c b/src/modules/module_utils.c
index b6d938f..1ce1641 100644
--- a/src/modules/module_utils.c
+++ b/src/modules/module_utils.c
@@ -457,20 +457,22 @@ 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]->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");
- 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 <=
- [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