OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git commits / 561934a

Fix double-free: guard against double-destroy of connection
cleanup() was called from conn.on('close'), then called conn.destroy() on an already-destroyed connection. The double destroy triggers a native double-free in libudx/SecretStream. Fix: check conn.destroyed before calling destroy(), and prevent re-entrant cleanup calls with a guard flag. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
561934a6eb5e2c1c888310d4ec6ade9a81610487
by plankatron <fleeky@gmail.com> · 2026-04-07T13:56:27.000Z

Changed files (1) +6 -1

bin/git-remote-punch +6 -1
……@@ -168,11 +168,16 @@ async function handleConnect(service, serverKey, repoName, httpsUrl, stdout, std
168168 // This ensures '\n' precedes ref advertisement on stdout
169169 stdout.write('\n')
170170
171 let cleaningUp = false
171172 function cleanup (code) {
173 if (cleaningUp) return
174 cleaningUp = true
172175 // Hard kill safety — if async teardown hangs, don't spin forever
173176 const hardKill = setTimeout(() => process.exit(code), 5000)
174177 hardKill.unref()
175 try { conn.destroy() } catch {}
178 // Don't destroy conn if already destroyed — double-destroy triggers
179 // native double-free in libudx/SecretStream teardown.
180 if (!conn.destroyed) try { conn.destroy() } catch {}
176181 connector.destroy().catch(() => {}).finally(() => {
177182 clearTimeout(hardKill)
178183 process.exit(code)