changeset 1560:ec55cdf44335

Fix a memory leak in hlog_get_log_jid()
author Mikael Berthe <mikael@lilotux.net>
date Fri, 17 Oct 2008 18:55:58 +0200
parents 0674abda9a8f
children 2e86c1cc4eb1
files mcabber/src/histolog.c
diffstat 1 files changed, 6 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/histolog.c	Sat Oct 11 10:56:30 2008 +0200
+++ b/mcabber/src/histolog.c	Fri Oct 17 18:55:58 2008 +0200
@@ -70,22 +70,20 @@
   char *log_jid = NULL;
 
   path = user_histo_file(bjid);
-  do {
+  while (path) {
     if (lstat(path, &bufstat) != 0)
       break;
     if (S_ISLNK(bufstat.st_mode)) {
       g_free(log_jid);
-      log_jid = g_new(char, bufstat.st_size+1);
+      log_jid = g_new0(char, bufstat.st_size+1);
       readlink(path, log_jid, bufstat.st_size);
       g_free(path);
-      log_jid[bufstat.st_size] = '\0';
       path = user_histo_file(log_jid);
-    } else {
-      g_free(path);
-      path = NULL;
-    }
-  } while( path );
+    } else
+      break;
+  }
 
+  g_free(path);
   return log_jid;
 }