Skip to content

Every invocation leaks a 3.6MB dylib into tmpdir #556

Open

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

Activity

  1. franky47 commented on Jul 17, 2026

    @franky47
    ContributorAuthor

    This is an upstream issue in Bun:

    OpenTUI

  2. WakaTaira commented on Jul 18, 2026

    @WakaTaira

    For anyone hitting this before the Bun-side fix (oven-sh/bun#29587) lands: proposed an interim startup sweep that reaps hunk's stale leaked artifacts in #568. On Linux this leak filled a 16 GB tmpfs overnight with an agent polling hunk session every 2 s.

  3. snirt commented on Jul 19, 2026

    @snirt

    Confirmed still reproducible on v0.17.2 (Homebrew), macOS 26.5.2 (25F84), arm64.

    We found 16,093 leaked libopentui.dylib copies under the per-user macOS TMPDIR, consuming about 52 GiB. The trigger was repeated Hunk pager invocations from long-running LazyGit sessions.

    I upgraded from v0.17.0 to v0.17.2 and ran the isolated five-invocation repro. Result:

    • 5 invocations
    • 5 new dylibs
    • each 3,758,912 bytes
    • 18 MiB total

    The test used an isolated TMPDIR and cleaned it afterward. Thus v0.17.2 still leaks one dylib per invocation. Please consider reopening this issue until #568, or an equivalent fix, is merged and released.

  4. tolgaerdonmez commented on Jul 20, 2026

    @tolgaerdonmez

    This generated 650GB of tmp files in my system too.

  5. benvinegar commented on Jul 26, 2026

    @benvinegar
    Member

    Okay #590 should make a huge difference. It's in 0.17.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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