[PATCH] Free discarded sbuf in hook_add()
Repolho <[email protected]>
| Newsgroups | gmane.comp.window-managers.ratpoison.devel |
|---|---|
| Message-ID | <20130807173058.GB8501@darch> |
Note: this is a very insignificant leak due to how rarely addhook would be called in everyday usage, but it's a leak nonetheless, so I thought I'd mention it. hook.c:hook_add() fails to free sbuf containing command (allocated by actions.c:cmd_addhook()), when that command is already present in the hook, resulting in a leak every time the user tries to re-add the same command to a hook. To reproduce, add a command to a hook twice, for example, by running: $ ratpoison -c "addhook quit abort"; !# which results in (taken from valgrind's log): 46 (40 direct, 6 indirect) bytes in 1 blocks are definitely lost in loss record 73 of 200 at 0x4C2C04B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x41BDCE: xmalloc (main.c:74) by 0x41F625: sbuf_new (sbuf.c:30) by 0x4106A4: cmd_addhook (actions.c:5218) by 0x40A882: command (actions.c:2557) by 0x40AA70: cmd_colon (actions.c:2597) by 0x40A882: command (actions.c:2557) by 0x415B22: handle_key (events.c:423) by 0x415BD8: key_press (events.c:459) by 0x416663: delegate_event (events.c:840) by 0x416AF5: listen_for_events (events.c:1008) by 0x41D187: main (main.c:749) 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
addhook_leak.patch
(text/x-diff, 481 B)
diff -pdru ratpoison/src/hook.c ratpoison.build/src/hook.c
--- ratpoison/src/hook.c 2013-08-07 12:08:11.161005020 -0300
+++ ratpoison.build/src/hook.c 2013-08-07 13:18:16.804773548 -0300
@@ -34,7 +34,10 @@ hook_add (struct list_head *hook, struct
list_for_each_entry (cur, hook, node)
{
if (!strcmp (sbuf_get (cur), sbuf_get (s)))
- return;
+ {
+ sbuf_free (s);
+ return;
+ }
}
/* It's not in the list, so add it. */