Fix a memory leak in hlog_get_log_jid()
authorMikael Berthe <mikael@lilotux.net>
Fri, 17 Oct 2008 18:55:58 +0200
changeset 1560 ec55cdf44335
parent 1559 0674abda9a8f
child 1561 2e86c1cc4eb1
Fix a memory leak in hlog_get_log_jid()
mcabber/src/histolog.c
--- 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;
 }