File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,47 @@ pull request will be accepted with a high degree of certainty.
133133
134134See the [ Contributor's Guide] ( po/README_CONTRIBUTORS.md ) for more details.
135135
136+ ## Checking for Memory Leaks
137+
138+ While Zig does an amazing job of finding and preventing memory leaks,
139+ Ghostty uses many third-party libraries that are written in C. Improper usage
140+ of those libraries or bugs in those libraries can cause memory leaks that
141+ Zig cannot detect by itself.
142+
143+ ### On Linux
144+
145+ On Linux the recommended tool to check for memory leaks is Valgrind. We supply
146+ a file containing suppressions for false positives and known leaks in 3rd party
147+ libraries. The recommended way to run Valgrind is:
148+
149+ ```
150+ zig build -Dcpu=baseline -Doptimize=Debug
151+ valgrind \
152+ --leak-check=full \
153+ --num-callers=50 \
154+ --suppressions=valgrind.supp \
155+ ./zig-out/bin/ghostty
156+ ```
157+
158+ > [ !NOTE]
159+ >
160+ > ` -Dcpu=baseline ` may not be needed depending on your CPU, but Valgrind cannot
161+ > deal with some instructions on certain newer CPUs so using ` -Dcpu=baseline `
162+ > doesn't hurt.
163+
164+ Any leaks found by Valgrind should be investigated.
165+
166+ If you use Nix, you can use the following commands to run Valgrind so that you
167+ don't need to look up the Valgrind invocation every time:
168+
169+ ```
170+ nix develop
171+ nix run .#valgrind -- --config-default-files=true
172+ ```
173+
174+ You can add any Ghostty CLI arguments after the ` -- ` and they will be passed to
175+ the invocation of Ghostty.
176+
136177## Input Stack Testing
137178
138179The input stack is the part of the codebase that starts with a
Original file line number Diff line number Diff line change 9494 x11-gnome = runVM ./nix/vm/x11-gnome.nix ;
9595 x11-plasma6 = runVM ./nix/vm/x11-plasma6.nix ;
9696 x11-xfce = runVM ./nix/vm/x11-xfce.nix ;
97+ valgrind = let
98+ script = pkgs . writeShellScript "valgrind" ''
99+ zig build -Dcpu=baseline -Doptimize=Debug
100+ valgrind \
101+ --leak-check=full \
102+ --num-callers=50 \
103+ --suppressions=valgrind.supp \
104+ ./zig-out/bin/ghostty "$@"
105+ '' ;
106+ in {
107+ type = "app" ;
108+ program = "${ script } " ;
109+ } ;
97110 } ;
98111 }
99112 # Our supported systems are the same supported systems as the Zig binaries.
You can’t perform that action at this time.
0 commit comments