[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/4] replace in load_output_modules if/else statement with simple
From: |
Andrei Kholodnyi |
Subject: |
[PATCH 2/4] replace in load_output_modules if/else statement with simple if |
Date: |
Tue, 5 Oct 2010 00:00:13 +0200 |
if {
...
return NULL;
} else {
...
}
replaced with
if {
...
return NULL;
}
local for else scope variables moved to the beginning of the function
to avoid multiple g_frees of rep_line after error conditions,
repl_line = NULL now, it will be anyway allocated in spd_getline
---
src/server/module.c | 143 ++++++++++++++++++++++++++-------------------------
1 files changed, 73 insertions(+), 70 deletions(-)
diff --git a/src/server/module.c b/src/server/module.c
index 0c4157d..1bb1109 100644
--- a/src/server/module.c
+++ b/src/server/module.c
@@ -52,6 +52,11 @@ load_output_module(char* mod_name, char* mod_prog, char*
mod_cfgfile, char* mod_
int cfg = 0;
int ret;
char *module_conf_dir;
+ char *rep_line = NULL;
+ FILE *f;
+ size_t n = 0;
+ char s;
+ GString *reply;
if (mod_name == NULL) return NULL;
@@ -170,83 +175,81 @@ load_output_module(char* mod_name, char* mod_prog, char*
mod_cfgfile, char* mod_
MSG(1, "ERROR: Something wrong with %s, can't initialize",
module->name);
output_close(module);
return NULL;
- }else{
- char *rep_line = g_malloc(1024);
- FILE *f;
- size_t n = 1024;
- char s;
- GString *reply;
-
- reply = g_string_new("\n---------------\n");
- f = fdopen(dup(module->pipe_out[0]), "r");
- while(1){
- 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)
- g_free(rep_line);
- return NULL;
- }
- assert(rep_line != NULL);
- MSG(5, "Reply from output module: %d %s", n, rep_line);
- if (ret <= 4){
- MSG(1, "ERROR: Bad syntax from output module %s 2",
module->name);
- g_free(rep_line);
- return NULL;
- }
-
- if (rep_line[3] != '-') {
- s = rep_line[0];
- g_free(rep_line);
- break;
- }
-
- g_string_append(reply, rep_line + 4);
- }
+ }
- if (SpeechdOptions.debug){
- MSG(4, "Switching debugging on for output module %s",
module->name);
- output_module_debug(module);
- }
- /* Initialize audio settings */
- ret = output_send_audio_settings(module);
- if (ret !=0){
- MSG(1, "ERROR: Can't initialize audio in output module, see reason
above.");
- module->working = 0;
- kill(module->pid, 9);
- waitpid(module->pid, NULL, WNOHANG);
- destroy_module(module);
+ reply = g_string_new("\n---------------\n");
+ f = fdopen(dup(module->pipe_out[0]), "r");
+ while(1){
+ 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)
+ g_free(rep_line);
return NULL;
}
-
- /* Send log level configuration setting */
- ret = output_send_loglevel_setting(module);
- if (ret !=0){
- MSG(1, "ERROR: Can't set the log level inin the output module.");
- module->working = 0;
- kill(module->pid, 9);
- waitpid(module->pid, NULL, WNOHANG);
- destroy_module(module);
+ assert(rep_line != NULL);
+ MSG(5, "Reply from output module: %d %s", n, rep_line);
+ if (ret <= 4){
+ MSG(1, "ERROR: Bad syntax from output module %s 2", module->name);
+ g_free(rep_line);
return NULL;
- }
+ }
- /* Get a list of supported voices */
- _output_get_voices(module);
- fclose(f);
- g_string_append_printf(reply, "---------------\n");
-
- if (s == '2') MSG(2, "Module %s started sucessfully with message: %s",
module->name, reply->str);
- else if (s == '3'){
- MSG(1, "ERROR: Module %s failed to initialize. Reason: %s",
module->name, reply->str);
- module->working = 0;
- kill(module->pid, 9);
- waitpid(module->pid, NULL, WNOHANG);
- destroy_module(module);
- return NULL;
- }
- g_string_free(reply, 1);
+ if (rep_line[3] != '-') {
+ s = rep_line[0];
+ g_free(rep_line);
+ break;
+ }
+
+ g_string_append(reply, rep_line + 4);
+ }
+
+ if (SpeechdOptions.debug){
+ MSG(4, "Switching debugging on for output module %s", module->name);
+ output_module_debug(module);
+ }
+
+ /* Initialize audio settings */
+ ret = output_send_audio_settings(module);
+ if (ret !=0){
+ MSG(1, "ERROR: Can't initialize audio in output module, see reason
above.");
+ module->working = 0;
+ kill(module->pid, 9);
+ waitpid(module->pid, NULL, WNOHANG);
+ destroy_module(module);
+ return NULL;
+ }
+
+ /* Send log level configuration setting */
+ ret = output_send_loglevel_setting(module);
+ if (ret !=0){
+ MSG(1, "ERROR: Can't set the log level inin the output module.");
+ module->working = 0;
+ kill(module->pid, 9);
+ waitpid(module->pid, NULL, WNOHANG);
+ destroy_module(module);
+ return NULL;
+ }
+
+ /* Get a list of supported voices */
+ _output_get_voices(module);
+ fclose(f);
+ g_string_append_printf(reply, "---------------\n");
+
+ if (s == '3'){
+ MSG(1, "ERROR: Module %s failed to initialize. Reason: %s",
module->name, reply->str);
+ module->working = 0;
+ kill(module->pid, 9);
+ waitpid(module->pid, NULL, WNOHANG);
+ destroy_module(module);
+ return NULL;
}
+ if (s == '2')
+ MSG(2, "Module %s started sucessfully with message: %s", module->name,
reply->str);
+
+ g_string_free(reply, 1);
+
return module;
}
--
1.6.0.4