speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH (speechd) 4/4] Restructure logging_init to eliminate multiple ret


From: Christopher Brannon
Subject: [PATCH (speechd) 4/4] Restructure logging_init to eliminate multiple returns.
Date: Fri, 19 Feb 2010 09:50:12 -0600

When I "fixed" the memory leak in logging_init, I forgot that the function
had multiple return statements.  This patch eliminates them by restructuring
the code.  Now, logging_init only returns at one point.

If the requested logfile could not be opened, the previous version would
incorrectly report that it was logging to the given file.  Fixed.
---
 src/server/speechd.c |   22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/src/server/speechd.c b/src/server/speechd.c
index 22ba075..7a4fe7d 100644
--- a/src/server/speechd.c
+++ b/src/server/speechd.c
@@ -756,26 +756,24 @@ logging_init(void)
   assert(file_name != NULL);
   if (!strncmp(file_name,"stdout",6)){
     logfile = stdout;
-    return;
-  }
-  if (!strncmp(file_name,"stderr",6)){
+  } else if (!strncmp(file_name, "stderr", 6)) {
     logfile = stderr;
-    return;
-  }
-  logfile = fopen(file_name, "a");
-  if (logfile == NULL){
-    fprintf(stderr, "Error: can't open logging file %s! Using stdout.\n",
-           file_name);
-    logfile = stdout;
+  } else {
+    logfile = fopen(file_name, "a");
+    if (logfile == NULL){
+      fprintf(stderr, "Error: can't open logging file %s! Using stdout.\n",
+             file_name);
+      logfile = stdout;
+    } else {
+      MSG(2,"Speech Dispatcher Logging to file %s", file_name);
+    }
   }
 
   if (!debug_logfile)
     debug_logfile = stdout;
 
-  MSG(2,"Speech Dispatcher Logging to file %s", file_name);
   g_free(file_name);
   return;
-
 }
 
 
-- 
1.6.6.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]