[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] fix rep_line memory leaks in module.c
From: |
Andrei Kholodnyi |
Subject: |
[PATCH 2/2] fix rep_line memory leaks in module.c |
Date: |
Wed, 29 Sep 2010 23:55:35 +0200 |
- there were 2 memory leaks while return
- n used now instead of strlen
- n checked for initial value to avoid unnecessary g_realloc
- if/else replaced with if statement with break inside
---
src/server/module.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/server/module.c b/src/server/module.c
index d0d4d06..85cce4e 100644
--- a/src/server/module.c
+++ b/src/server/module.c
@@ -179,22 +179,27 @@ load_output_module(char* mod_name, char* mod_prog, char*
mod_cfgfile, char* mod_
ret = spd_getline(&rep_line, &n, f);
if (ret <= 0){
MSG(1, "ERROR: Bad syntax from output module %s 1",
module->name);
+ if (rep_line != NULL)
+ free(rep_line);
return NULL;
}
assert(rep_line != NULL);
MSG(5, "Reply from output module: %d %s", n, rep_line);
- if (strlen(rep_line) <= 4){
+ if (n <= 4){
MSG(1, "ERROR: Bad syntax from output module %s 2",
module->name);
+ g_free(rep_line);
return NULL;
}
- if (rep_line[3] == '-') g_string_append(reply, rep_line + 4);
- else{
+ if (rep_line[3] != '-') {
s = rep_line[0];
g_free(rep_line);
break;
}
+ g_string_append(reply, rep_line + 4);
+ if (n < 1024)
+ n = 1024;
}
if (SpeechdOptions.debug){
--
1.6.0.4