Skip to content

Every invocation leaks a 3.6MB dylib into tmpdir #556

Description

@franky47

What happened?

Each run of hunk extracts its embedded libopentui.dylib into $TMPDIR as a hidden file named .{hash}-00000000.dylib (3.6MB). The file gets a unique random name on every run and is never deleted, even when hunk exits cleanly.

This adds up fast when hunk is used as a git pager. With lazygit spawning git diff | hunk pager on every refresh, my machine accumulated 81,653 of these files (about 190GB) in three weeks, at a rate of roughly 18 files per minute while lazygit was open (which I often leave open in a cmux pane, one per workspace).

The files identify as OpenTUI's native library:

$ codesign -dv .5ccbd3e7f7bf5fff-00000000.dylib
Identifier=libopentui.dylib
Format=Mach-O thin (arm64)
Signature=adhoc

This looks like Bun's single-file executable behaviour: embedded native addons are extracted to TMPDIR at startup, and the randomized filename prevents reuse across runs. Since cleanup doesn't happen either, every invocation adds a new copy.

Reproduced on v0.17.0 (Homebrew) and v0.17.1 (release binary hunkdiff-darwin-arm64), macOS 15 (Darwin 24.6.0), Apple Silicon.

Steps to reproduce

#!/usr/bin/env bash
set -euo pipefail

REPRO_TMP="$(mktemp -d)"
trap 'rm -rf "$REPRO_TMP"' EXIT

DIFF=$(cat <<'EOF'
diff --git a/foo.txt b/foo.txt
index 0000000..1111111 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-hello
+world
EOF
)

for i in 1 2 3 4 5; do
  TMPDIR="$REPRO_TMP/" hunk pager <<<"$DIFF" > /dev/null 2>&1
done

find "$REPRO_TMP" -name '.*.dylib' -exec ls -la {} +

Output on my machine: 5 runs leave 5 files, 18MB total.

-rw-r--r--@ 1 franky staff 3758912 .9bdbb2fbe532eefb-00000000.dylib
-rw-r--r--@ 1 franky staff 3758912 .9bdbb2fbeeafdefb-00000000.dylib
-rw-r--r--@ 1 franky staff 3758912 .9bdbb2fbf7afcfbb-00000000.dylib
...

Expected behavior

Temp files are removed on exit, or extracted to a stable path that gets reused across runs instead of duplicated.

Version

0.17.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions