[PATCH] Free string allocated by getline() in history_load()

Repolho <[email protected]>
Newsgroups gmane.comp.window-managers.ratpoison.devel
Message-ID <20130807173225.GC8501@darch>
Note: this is another very minor leak, since it only happens once while loading
the history file, but I thought I'd throw it in as well.

history.c:history_load() calls getline(), but fails to free the string
allocated by that function.

To reproduce, simply run ratpoison with a valid ~/.ratpoison_history file,
which results in (taken from valgrind's log):

120 bytes in 1 blocks are definitely lost in loss record 125 of 193
   at 0x4C2C04B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x5C11A2D: getdelim (in /usr/lib/libc-2.17.so)
   by 0x41A155: history_load (history.c:195)
   by 0x41D0A2: main (main.c:720)

The attached patch fixes the issue. It was generated over the latest git,
v1.4.6-48-gb02d855.

_______________________________________________
Ratpoison-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/ratpoison-devel
history_load_leak.patch (text/x-diff, 510 B)
diff -pdru ratpoison/src/history.c ratpoison.build/src/history.c
--- ratpoison/src/history.c	2013-08-07 12:08:11.160005043 -0300
+++ ratpoison.build/src/history.c	2013-08-07 13:47:38.988040803 -0300
@@ -201,6 +201,8 @@ history_load (void)
     /* defaults.history_size might be only set later */
     history_add_upto (hist_COMMAND, line, INT_MAX);
   }
+  if (line)
+      free(line);
   if (ferror (f)) {
     PRINT_DEBUG (("ratpoison: error reading %s - %s\n", filename, strerror (errno)));
     fclose(f);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.