speechd-discuss
[Top][All Lists]
Advanced

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

[PATCH (speechd) 3/3] Repare two tiny memory leaks.


From: Christopher Brannon
Subject: [PATCH (speechd) 3/3] Repare two tiny memory leaks.
Date: Sun, 14 Feb 2010 15:57:52 -0600

In the function logging_init, a block is allocated, and a pointer is
stored in file_name.  The pointer is lost as soon as the function returns.

In main, from src/server/speechd.c,
g_path_get_dirname() was used as an argument to mkdir.  g_path_get_dirname
returns a pointer to an allocated string, and that pointer was lost as
soon as mkdir returned.
Instead, I placed it in a temporary variable, freeing it after mkdir.
---
 src/server/speechd.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/src/server/speechd.c b/src/server/speechd.c
index e7f36e5..22ba075 100644
--- a/src/server/speechd.c
+++ b/src/server/speechd.c
@@ -773,6 +773,7 @@ logging_init(void)
     debug_logfile = stdout;
 
   MSG(2,"Speech Dispatcher Logging to file %s", file_name);
+  g_free(file_name);
   return;
 
 }
@@ -855,9 +856,11 @@ main(int argc, char *argv[])
 
     if (SpeechdOptions.pid_file == NULL){
       if (SpeechdOptions.home_speechd_dir){    
+       char *temp = NULL;
        SpeechdOptions.pid_file = 
g_strdup_printf("%s/pid/speech-dispatcher.pid",
                                                  
SpeechdOptions.home_speechd_dir);
-       mkdir(g_path_get_dirname(SpeechdOptions.pid_file), S_IRWXU);
+       temp = g_path_get_dirname(SpeechdOptions.pid_file);
+       mkdir(temp, S_IRWXU);
       }else if (!strcmp(PIDPATH, ""))
        SpeechdOptions.pid_file = strdup("/var/run/speech-dispatcher.pid");
       else
-- 
1.6.6.1




reply via email to

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