[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] mem allocation
From: |
José Vilmar Estácio de Souza |
Subject: |
[PATCH] mem allocation |
Date: |
Sat, 20 Feb 2010 17:08:32 -0200 |
change calls to malloc and free for g_malloc and g_free.
Also exchanged a few calls to strdup by g_strdup.
This was done because in some situations memory allocated with malloc command
was being released with the command g_free.
---
src/modules/ibmtts.c | 16 ++++++++--------
src/modules/module_utils.c | 20 ++++++++++----------
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/src/modules/ibmtts.c b/src/modules/ibmtts.c
index 7169a02..e566250 100644
--- a/src/modules/ibmtts.c
+++ b/src/modules/ibmtts.c
@@ -592,11 +592,11 @@ module_speak(gchar *data, size_t bytes, EMessageType
msgtype)
/* Strip all SSML */
char *tmp = *ibmtts_message;
*ibmtts_message = module_strip_ssml(*ibmtts_message);
- g_free(tmp);
+ xfree(tmp);
/* Convert input to suitable encoding for current language
dialect */
tmp = g_convert_with_fallback(*ibmtts_message, -1,
ibmtts_input_encoding, "utf-8", "?", NULL, &bytes, NULL);
if (tmp != NULL) {
- g_free(*ibmtts_message);
+ xfree(*ibmtts_message);
*ibmtts_message = tmp;
}
}
@@ -1662,8 +1662,8 @@ alloc_voice_list()
if (eciGetAvailableLanguages(aLanguage, &nLanguages))
return;
- ibmtts_voice_list = malloc((nLanguages+1)*sizeof(VoiceDescription*));
- ibmtts_voice_index = malloc((nLanguages+1)*sizeof(VoiceDescription*));
+ ibmtts_voice_list = xmalloc((nLanguages+1)*sizeof(VoiceDescription*));
+ ibmtts_voice_index = xmalloc((nLanguages+1)*sizeof(VoiceDescription*));
if (!ibmtts_voice_list)
return;
@@ -1671,7 +1671,7 @@ alloc_voice_list()
for(i=0; i<nLanguages; i++) {
/* look for the language name */
int j;
- ibmtts_voice_list[i] = malloc(sizeof(VoiceDescription));
+ ibmtts_voice_list[i] = xmalloc(sizeof(VoiceDescription));
DBG("Ibmtts: aLanguage[%d]=0x%08x", i, aLanguage[i]);
for (j=0; j<MAX_NB_OF_LANGUAGES; j++) {
@@ -1697,7 +1697,7 @@ free_voice_list()
int i=0;
if (ibmtts_voice_index) {
- free(ibmtts_voice_index);
+ xfree(ibmtts_voice_index);
ibmtts_voice_index = NULL;
}
@@ -1705,10 +1705,10 @@ free_voice_list()
return;
for(i=0; ibmtts_voice_list[i]; i++) {
- free(ibmtts_voice_list[i]);
+ xfree(ibmtts_voice_list[i]);
}
- free(ibmtts_voice_list);
+ xfree(ibmtts_voice_list);
ibmtts_voice_list = NULL;
}
diff --git a/src/modules/module_utils.c b/src/modules/module_utils.c
index abce4c7..c74acb0 100644
--- a/src/modules/module_utils.c
+++ b/src/modules/module_utils.c
@@ -51,7 +51,7 @@ ssize_t getline (char **lineptr, size_t *n, FILE *f)
if ( m++ >= buf_len )
{
buf_len += BUFFER_LEN;
- buf = (char *) realloc(buf, buf_len + 1);
+ buf = (char *) xrealloc(buf, buf_len + 1);
if ( buf == NULL )
{
DBG("buf==NULL");
@@ -82,7 +82,7 @@ xmalloc(size_t size)
{
void *p;
- p = malloc(size);
+ p = g_malloc(size);
if (p == NULL) FATAL("Not enough memmory");
return p;
}
@@ -93,9 +93,9 @@ xrealloc(void *data, size_t size)
void *p;
if (data != NULL)
- p = realloc(data, size);
+ p = g_realloc(data, size);
else
- p = malloc(size);
+ p = xmalloc(size);
if (p == NULL) FATAL("Not enough memmory");
@@ -105,7 +105,7 @@ xrealloc(void *data, size_t size)
void
xfree(void *data)
{
- if (data != NULL) free(data);
+ if (data != NULL) g_free(data);
}
char*
@@ -131,7 +131,7 @@ do_message(EMessageType msgtype)
if (!strcmp(cur_line, "..\n")){
xfree(cur_line);
- cur_line = strdup(".\n");
+ cur_line = g_strdup(".\n");
}else if (!strcmp(cur_line, ".\n")){
/* Strip the trailing \n */
msg->str[strlen(msg->str)-1] = 0;
@@ -716,7 +716,7 @@ module_parent_wfork(TModuleDoublePipe dpipe, const char*
message, EMessageType m
DBG("Entering parent process, closing pipes");
- buf = (char*) malloc((maxlen+1) * sizeof(char));
+ buf = (char*) xmalloc((maxlen+1) * sizeof(char));
module_parent_dp_init(dpipe);
@@ -950,7 +950,7 @@ module_semaphore_init()
sem_t *semaphore;
int ret;
- semaphore = (sem_t *) malloc(sizeof(sem_t));
+ semaphore = (sem_t *) xmalloc(sizeof(sem_t));
if (semaphore == NULL) return NULL;
ret = sem_init(semaphore, 0, 0);
if (ret != 0){
@@ -1056,7 +1056,7 @@ module_add_config_option(configoption_t *options, int
*num_options, char *name,
assert(name != NULL);
num_config_options++;
- opts = (configoption_t*) realloc(options, (num_config_options+1) *
sizeof(configoption_t));
+ opts = (configoption_t*) xrealloc(options, (num_config_options+1) *
sizeof(configoption_t));
opts[num_config_options-1].name = (char*) strdup(name);
opts[num_config_options-1].type = type;
opts[num_config_options-1].callback = callback;
@@ -1088,7 +1088,7 @@ add_config_option(configoption_t *options, int
*num_config_options, char *name,
configoption_t *opts;
(*num_config_options)++;
- opts = (configoption_t*) realloc(options, (*num_config_options) *
sizeof(configoption_t));
+ opts = (configoption_t*) xrealloc(options, (*num_config_options) *
sizeof(configoption_t));
opts[*num_config_options-1].name = strdup(name);
opts[*num_config_options-1].type = type;
opts[*num_config_options-1].callback = callback;
--
1.6.3.3
--------------090004040602040309070302--
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] mem allocation,
José Vilmar Estácio de Souza <=