"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Kyle Ackerman <kackerman0102@gmail.com>
Subject:
Got status memory leak
To:
gameoftrees@openbsd.org
Date:
Sat, 02 Dec 2023 19:10:15 -0600

Download raw body.

Thread
Here is the method to my madness for finding the memory leak.  I used
Otto's malloc on got to identify memory leaks.  Here is the kdump of
running `got status`.

******** Start dump got *******
M=8 I=1 F=0 U=0 J=1 R=0 X=0 C=0 cache=64 G=0
Leak report:
                 f     sum      #    avg
     0x75ae9750e5f     384      8     48 addr2line -e got 0x5be5f
     0x75ae976dd27      32      1     32 addr2line -e got 0x78d27
     0x75ae9785cc8      32      2     16 addr2line -e got 0x90cc8
     0x75ae978acdc      96      1     96 addr2line -e got 0x95cdc
     0x75ae978b449      80      3     26 addr2line -e got 0x96449
     0x75ae97b8cda      48      1     48 addr2line -e got 0xc3cda
     0x75db48c0b3f     128      1    128 addr2line -e /usr/lib/libc.so.97.1 0xb4b3f
     0x75db48c3833   65536      1  65536 addr2line -e /usr/lib/libc.so.97.1 0xb7833
     0x75db48dbd71     144      8     18 addr2line -e /usr/lib/libc.so.97.1 0xcfd71
     0x75db48dd7d0      64      1     64 addr2line -e /usr/lib/libc.so.97.1 0xd17d0

******** End dump got *******

The reason for the memory leak is that the worktree is never
closed/freed.  Here is the diff that closes the worktree.

diff /home/kyle/src/gotfork
commit - 1772f6cfbdaab8df400578320b52df07c48c5351
path + /home/kyle/src/gotfork
blob - 1f980e0d7946002349e8aa40fa0eedcdfbd92322
file + got/got.c
--- got/got.c
+++ got/got.c
@@ -6519,6 +6519,7 @@ done:
 
 	got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH);
 	free(cwd);
+	got_worktree_close(worktree);
 	return error;
 }
 

Here is the kdump result after applying the patch above.

******** Start dump got *******
M=8 I=1 F=0 U=0 J=1 R=0 X=0 C=0 cache=64 G=0
Leak report:
                 f     sum      #    avg
     0x60a067e5e7f     384      8     48 addr2line -e got 0x5be7f
     0x60a0681ace8      32      2     16 addr2line -e got 0x90ce8
     0x60cfe855833   65536      1  65536 addr2line -e /usr/lib/libc.so.97.1 0xb7833
     0x60cfe86dd71     112      7     16 addr2line -e /usr/lib/libc.so.97.1 0xcfd71
     0x60cfe86f7d0      64      1     64 addr2line -e /usr/lib/libc.so.97.1 0xd17d0

******** End dump got *******

I will now be on a quest of plugging the remaining leaks.  Maybe someone can track
down the leaks coming from imsg.