From: Kyle Ackerman Subject: Got Status Memory Leak pt. 3 To: gameoftrees@openbsd.org Date: Thu, 07 Dec 2023 12:53:06 -0600 Here is the grand finale of this series. Here is the kdump from running `got status` ******** Start dump got ******* M=8 I=1 F=1 U=1 J=2 R=0 X=0 C=0xfe64220e cache=0 G=4096 Leak report: f sum # avg 0x17999bcc60 64 1 64 addr2line -e /usr/lib/libc.so.97.1 0x49c60 0x17999e3da1 112 7 16 addr2line -e /usr/lib/libc.so.97.1 0x70da1 0x1799a14b53 69632 1 69632 addr2line -e /usr/lib/libc.so.97.1 0xa1b53 0x14f1abad78 32 2 16 addr2line -e /home/kyle/bin/got 0x90d78 ******** End dump got ******* The got_pathlist_head never gets cleaned up in free_ignores(). The patch below will free it. While freeing the ignorelist in the TAILQ_FOREACH loop, the head of the list doesn't get freed. The puzzling part to me is that got_pathlist_free(ignores, GOT_PATHLIST_FREE_ALL) does not plug the leak, seems to reduce it though. But freeing it after the ignorelist seems to work. This patch has passed all regressions on my end. diff /home/kyle/src/got-dev commit - 6ecb0b8c6b2aa36b6af31c856909b1ddccdb301c path + /home/kyle/src/got-dev blob - 4415674d74999e7b6fef5dd651fa76682cc19ca1 file + lib/worktree.c --- lib/worktree.c +++ lib/worktree.c @@ -3721,6 +3721,7 @@ free_ignores(struct got_pathlist_head *ignores) struct got_pathlist_head *ignorelist = pe->data; got_pathlist_free(ignorelist, GOT_PATHLIST_FREE_PATH); + free(ignorelist); } got_pathlist_free(ignores, GOT_PATHLIST_FREE_PATH); } @@ -3777,6 +3778,7 @@ done: if (err || pe == NULL) { free(dirpath); got_pathlist_free(ignorelist, GOT_PATHLIST_FREE_PATH); + free(ignorelist); } return err; } Here is the kdump of `got status` after the patch is applied. ******** Start dump got ******* M=8 I=1 F=1 U=1 J=2 R=0 X=0 C=0x3c2d4632 cache=0 G=4096 Leak report: f sum # avg 0xb88c3283c60 64 1 64 addr2line -e /usr/lib/libc.so.97.1 0x49c60 0xb88c32aada1 112 7 16 addr2line -e /usr/lib/libc.so.97.1 0x70da1 0xb88c32dbb53 69632 1 69632 addr2line -e /usr/lib/libc.so.97.1 0xa1b53 ******** End dump got ******* Comments/sugguestions/oks?